Plany: wizard 3-etapowy tworzenia/edycji, silownia i alias tygodnia (UX + API + migracja)
This commit is contained in:
@@ -54,9 +54,7 @@ export function useBodyParameters() {
|
||||
return useQuery({
|
||||
queryKey: ['me', 'body-parameters'],
|
||||
queryFn: () =>
|
||||
api<{ weight: WeightPoint[]; circumferences: CircumferenceSeries[] }>(
|
||||
'/me/body-parameters',
|
||||
),
|
||||
api<{ weight: WeightPoint[]; circumferences: CircumferenceSeries[] }>('/me/body-parameters'),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -71,12 +69,18 @@ function toIsoDate(date: string | undefined): string | undefined {
|
||||
|
||||
export function addWeight(value: number, date?: string) {
|
||||
const iso = toIsoDate(date);
|
||||
return api('/me/body-parameters/weight', { method: 'POST', body: { value, ...(iso ? { date: iso } : {}) } });
|
||||
return api('/me/body-parameters/weight', {
|
||||
method: 'POST',
|
||||
body: { value, ...(iso ? { date: iso } : {}) },
|
||||
});
|
||||
}
|
||||
|
||||
export function addCircumference(name: string, value: number, date?: string) {
|
||||
const iso = toIsoDate(date);
|
||||
return api('/me/body-parameters/circumference', { method: 'POST', body: { name, value, ...(iso ? { date: iso } : {}) } });
|
||||
return api('/me/body-parameters/circumference', {
|
||||
method: 'POST',
|
||||
body: { name, value, ...(iso ? { date: iso } : {}) },
|
||||
});
|
||||
}
|
||||
|
||||
export function removeWeightPoint(id: string) {
|
||||
@@ -126,10 +130,9 @@ export function useGymDetail(id: string | undefined) {
|
||||
export function addGymPhotos(gymId: string, files: File[]) {
|
||||
const form = new FormData();
|
||||
for (const f of files) form.append('photos', f);
|
||||
return api<{ gym: Gym & { photos: { id: string; url: string; order: number; createdAt: string }[] } }>(
|
||||
`/gyms/${gymId}/photos`,
|
||||
{ method: 'POST', body: form },
|
||||
);
|
||||
return api<{
|
||||
gym: Gym & { photos: { id: string; url: string; order: number; createdAt: string }[] };
|
||||
}>(`/gyms/${gymId}/photos`, { method: 'POST', body: form });
|
||||
}
|
||||
|
||||
export function deleteGymPhoto(gymId: string, photoId: string) {
|
||||
@@ -224,7 +227,10 @@ export function useGymExceptions(gymId: string) {
|
||||
});
|
||||
}
|
||||
|
||||
export function createGymException(gymId: string, body: { date: string; availability: { start: string; end: string } | null }) {
|
||||
export function createGymException(
|
||||
gymId: string,
|
||||
body: { date: string; availability: { start: string; end: string } | null },
|
||||
) {
|
||||
return api<{ exception: GymException }>(`/gyms/${gymId}/exceptions`, {
|
||||
method: 'POST',
|
||||
body,
|
||||
@@ -323,17 +329,26 @@ export function useGymInviteeSearch(gymId: string, firstName: string, lastName:
|
||||
|
||||
/** List the equipment (machine/device) catalog. */
|
||||
export function useEquipment() {
|
||||
return useQuery({ queryKey: ['equipment'], queryFn: () => api<{ equipment: Equipment[] }>('/equipment') });
|
||||
return useQuery({
|
||||
queryKey: ['equipment'],
|
||||
queryFn: () => api<{ equipment: Equipment[] }>('/equipment'),
|
||||
});
|
||||
}
|
||||
|
||||
// ---------- exercises ----------
|
||||
export function useExercises() {
|
||||
return useQuery({ queryKey: ['exercises'], queryFn: () => api<{ exercises: Exercise[] }>('/exercises') });
|
||||
return useQuery({
|
||||
queryKey: ['exercises'],
|
||||
queryFn: () => api<{ exercises: Exercise[] }>('/exercises'),
|
||||
});
|
||||
}
|
||||
|
||||
// ---------- focus areas (priorities/exclusions) ----------
|
||||
export function useFocusAreas() {
|
||||
return useQuery({ queryKey: ['focus-areas'], queryFn: () => api<{ focusAreas: FocusArea[] }>('/focus-areas') });
|
||||
return useQuery({
|
||||
queryKey: ['focus-areas'],
|
||||
queryFn: () => api<{ focusAreas: FocusArea[] }>('/focus-areas'),
|
||||
});
|
||||
}
|
||||
|
||||
export function useFocusChain() {
|
||||
@@ -378,20 +393,26 @@ export interface PlanDayInput {
|
||||
|
||||
export interface PlanWeekInput {
|
||||
index: number;
|
||||
/** Opcjonalny alias tygodnia (np. „Deload"); null = bez aliasu. */
|
||||
customName?: string | null;
|
||||
days: PlanDayInput[];
|
||||
}
|
||||
|
||||
export function createPlan(body: {
|
||||
export interface PlanBody {
|
||||
title: string;
|
||||
weeksCount: number;
|
||||
/** Informacyjna — siłownia planu; null/brak = bez siłowni. */
|
||||
gymId?: string | null;
|
||||
weeks: PlanWeekInput[];
|
||||
/** Opcjonalna data startu (poniedziałek) — plan tworzony i aktywowany w jednym kroku. */
|
||||
startDate?: string;
|
||||
}) {
|
||||
}
|
||||
|
||||
export function createPlan(body: PlanBody) {
|
||||
return api<{ plan: { id: string } }>('/plans', { method: 'POST', body });
|
||||
}
|
||||
|
||||
export function updatePlan(id: string, body: { title: string; weeksCount: number; weeks: PlanWeekInput[] }) {
|
||||
export function updatePlan(id: string, body: Omit<PlanBody, 'startDate'>) {
|
||||
return api(`/plans/${id}`, { method: 'PATCH', body });
|
||||
}
|
||||
|
||||
@@ -439,7 +460,10 @@ export function addSessionExercise(sessionId: string, exerciseId: string) {
|
||||
});
|
||||
}
|
||||
|
||||
export function setSessionExerciseState(exerciseId: string, data: { hidden?: boolean; removed?: boolean }) {
|
||||
export function setSessionExerciseState(
|
||||
exerciseId: string,
|
||||
data: { hidden?: boolean; removed?: boolean },
|
||||
) {
|
||||
return api(`/sessions/exercises/${exerciseId}`, { method: 'PATCH', body: data });
|
||||
}
|
||||
|
||||
@@ -447,7 +471,15 @@ export function addSessionSet(exerciseId: string) {
|
||||
return api<{ setId: string }>(`/sessions/exercises/${exerciseId}/sets`, { method: 'POST' });
|
||||
}
|
||||
|
||||
export function updateSessionSet(setId: string, data: { reps?: number | null; rir?: number | null; difficulty?: number | null; note?: string | null }) {
|
||||
export function updateSessionSet(
|
||||
setId: string,
|
||||
data: {
|
||||
reps?: number | null;
|
||||
rir?: number | null;
|
||||
difficulty?: number | null;
|
||||
note?: string | null;
|
||||
},
|
||||
) {
|
||||
return api(`/sessions/sets/${setId}`, { method: 'PATCH', body: data });
|
||||
}
|
||||
|
||||
@@ -539,7 +571,10 @@ export function useTraineeSearch(firstName: string, lastName: string) {
|
||||
}
|
||||
|
||||
export function sendInvitation(userId: string) {
|
||||
return api<{ coaching: { id: string } }>('/trainer/invitations', { method: 'POST', body: { userId } });
|
||||
return api<{ coaching: { id: string } }>('/trainer/invitations', {
|
||||
method: 'POST',
|
||||
body: { userId },
|
||||
});
|
||||
}
|
||||
|
||||
export function archiveTrainee(userId: string) {
|
||||
@@ -569,9 +604,7 @@ export function useCalendar(month?: string) {
|
||||
return useQuery({
|
||||
queryKey: ['calendar', month],
|
||||
queryFn: () =>
|
||||
api<{ month: string; days: CalendarDay[] }>(
|
||||
`/calendar${month ? `?month=${month}` : ''}`,
|
||||
),
|
||||
api<{ month: string; days: CalendarDay[] }>(`/calendar${month ? `?month=${month}` : ''}`),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -617,13 +650,20 @@ export function addTraineeComment(
|
||||
userId: string,
|
||||
data: { body: string; sessionId?: string; sessionExerciseId?: string },
|
||||
) {
|
||||
return api<{ comment: ExerciseComment }>(`/trainer/trainees/${encodeURIComponent(userId)}/comments`, {
|
||||
method: 'POST',
|
||||
body: data,
|
||||
});
|
||||
return api<{ comment: ExerciseComment }>(
|
||||
`/trainer/trainees/${encodeURIComponent(userId)}/comments`,
|
||||
{
|
||||
method: 'POST',
|
||||
body: data,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export function addMyComment(data: { body: string; sessionId: string; sessionExerciseId?: string }) {
|
||||
export function addMyComment(data: {
|
||||
body: string;
|
||||
sessionId: string;
|
||||
sessionExerciseId?: string;
|
||||
}) {
|
||||
return api<{ comment: ExerciseComment }>('/me/comments', { method: 'POST', body: data });
|
||||
}
|
||||
|
||||
@@ -647,7 +687,8 @@ export function useExerciseProgress() {
|
||||
export function useTraineeExerciseProgress(userId: string) {
|
||||
return useQuery({
|
||||
queryKey: ['trainees', userId, 'exercise-progress'],
|
||||
queryFn: () => api<{ exercises: ExerciseProgress[] }>(`/trainer/trainees/${userId}/exercise-progress`),
|
||||
queryFn: () =>
|
||||
api<{ exercises: ExerciseProgress[] }>(`/trainer/trainees/${userId}/exercise-progress`),
|
||||
enabled: !!userId,
|
||||
});
|
||||
}
|
||||
@@ -655,7 +696,8 @@ export function useTraineeExerciseProgress(userId: string) {
|
||||
export function useTraineeLatestResults(userId: string) {
|
||||
return useQuery({
|
||||
queryKey: ['trainees', userId, 'exercise-latest'],
|
||||
queryFn: () => api<{ results: LatestExerciseResult[] }>(`/trainer/trainees/${userId}/exercise-latest`),
|
||||
queryFn: () =>
|
||||
api<{ results: LatestExerciseResult[] }>(`/trainer/trainees/${userId}/exercise-latest`),
|
||||
enabled: !!userId,
|
||||
});
|
||||
}
|
||||
@@ -677,20 +719,18 @@ export function useTraineePlan(userId: string, planId: string) {
|
||||
});
|
||||
}
|
||||
|
||||
export function createTraineePlan(
|
||||
userId: string,
|
||||
body: {
|
||||
title: string;
|
||||
weeksCount: number;
|
||||
weeks: PlanWeekInput[];
|
||||
/** Opcjonalna data startu (poniedziałek) — plan tworzony i aktywowany w jednym kroku. */
|
||||
startDate?: string;
|
||||
},
|
||||
) {
|
||||
return api<{ plan: { id: string } }>(`/trainer/trainees/${userId}/plans`, { method: 'POST', body });
|
||||
export function createTraineePlan(userId: string, body: PlanBody) {
|
||||
return api<{ plan: { id: string } }>(`/trainer/trainees/${userId}/plans`, {
|
||||
method: 'POST',
|
||||
body,
|
||||
});
|
||||
}
|
||||
|
||||
export function updateTraineePlan(userId: string, planId: string, body: { title: string; weeksCount: number; weeks: PlanWeekInput[] }) {
|
||||
export function updateTraineePlan(
|
||||
userId: string,
|
||||
planId: string,
|
||||
body: Omit<PlanBody, 'startDate'>,
|
||||
) {
|
||||
return api(`/trainer/trainees/${userId}/plans/${planId}`, { method: 'PATCH', body });
|
||||
}
|
||||
|
||||
@@ -699,7 +739,10 @@ export function deleteTraineePlan(userId: string, planId: string) {
|
||||
}
|
||||
|
||||
export function activateTraineePlan(userId: string, planId: string, startDate: string) {
|
||||
return api(`/trainer/trainees/${userId}/plans/${planId}/activate`, { method: 'POST', body: { startDate } });
|
||||
return api(`/trainer/trainees/${userId}/plans/${planId}/activate`, {
|
||||
method: 'POST',
|
||||
body: { startDate },
|
||||
});
|
||||
}
|
||||
|
||||
export function abandonTraineePlan(userId: string, planId: string) {
|
||||
|
||||
@@ -184,7 +184,12 @@ export interface GymInvitation {
|
||||
/** Kto został zaproszony (tylko direction = 'sent'). */
|
||||
user: { id: string; firstName: string | null; lastName: string | null; email: string } | null;
|
||||
/** Kto zaprosił (tylko direction = 'received'). */
|
||||
invitedBy: { id: string; firstName: string | null; lastName: string | null; email: string } | null;
|
||||
invitedBy: {
|
||||
id: string;
|
||||
firstName: string | null;
|
||||
lastName: string | null;
|
||||
email: string;
|
||||
} | null;
|
||||
invitedAt: string;
|
||||
expiresAt: string;
|
||||
}
|
||||
@@ -262,6 +267,8 @@ export interface PlanDay {
|
||||
export interface PlanWeek {
|
||||
id: string;
|
||||
index: number;
|
||||
/** Opcjonalny alias tygodnia (np. „Deload"). */
|
||||
customName: string | null;
|
||||
days: PlanDay[];
|
||||
}
|
||||
|
||||
@@ -271,6 +278,8 @@ export interface Plan {
|
||||
status: 'DRAFT' | 'ACTIVE' | 'COMPLETED' | 'ABANDONED';
|
||||
weeksCount: number;
|
||||
startDate: string | null;
|
||||
/** Informacyjna — siłownia, w której realizowany jest plan; null = bez siłowni. */
|
||||
gym: { id: string; name: string } | null;
|
||||
/** Kto utworzył plan (trener, gdy plan należy do podopiecznego); null = podopieczny sam. */
|
||||
creator: { id: string; firstName: string | null; lastName: string | null } | null;
|
||||
/** Podsumowanie postępu (lista planów); brak = dane niedostępne. */
|
||||
@@ -325,7 +334,11 @@ export interface ActiveSession {
|
||||
|
||||
export interface Dashboard {
|
||||
killstreak: number;
|
||||
nextTraining: { dayId: string; date: string; exercises: { name: string; muscle: string }[] } | null;
|
||||
nextTraining: {
|
||||
dayId: string;
|
||||
date: string;
|
||||
exercises: { name: string; muscle: string }[];
|
||||
} | null;
|
||||
progress: { completed: number; total: number; percent: number } | null;
|
||||
/** Serie wykonane ponad plan (planSetId = null) w ukończonych sesjach aktywnego planu. */
|
||||
extra: { sets: number } | null;
|
||||
@@ -353,7 +366,12 @@ export interface HistorySet {
|
||||
reps: number | null;
|
||||
rir: number | null;
|
||||
difficulty: number | null;
|
||||
planned: { reps: number | null; loadKg: number | null; restSec: number | null; rir: number | null } | null;
|
||||
planned: {
|
||||
reps: number | null;
|
||||
loadKg: number | null;
|
||||
restSec: number | null;
|
||||
rir: number | null;
|
||||
} | null;
|
||||
}
|
||||
|
||||
export interface ExerciseComment {
|
||||
@@ -418,7 +436,12 @@ export interface MessageAttachment {
|
||||
index: number;
|
||||
reps: number | null;
|
||||
rir: number | null;
|
||||
planned: { reps: number | null; loadKg: number | null; restSec: number | null; rir: number | null } | null;
|
||||
planned: {
|
||||
reps: number | null;
|
||||
loadKg: number | null;
|
||||
restSec: number | null;
|
||||
rir: number | null;
|
||||
} | null;
|
||||
}[];
|
||||
} | null;
|
||||
/** Tylko gdy exercise == null. */
|
||||
@@ -483,7 +506,11 @@ export interface UserSearchResult {
|
||||
export interface Trainee {
|
||||
user: { id: string; firstName: string | null; lastName: string | null; nickname: string | null };
|
||||
gyms: { id: string; name: string }[];
|
||||
activePlan: { id: string; title: string; progress: { completed: number; total: number; percent: number } } | null;
|
||||
activePlan: {
|
||||
id: string;
|
||||
title: string;
|
||||
progress: { completed: number; total: number; percent: number };
|
||||
} | null;
|
||||
killstreak: number;
|
||||
lastSessionAt: string | null;
|
||||
flags: TraineeFlag[];
|
||||
@@ -498,7 +525,11 @@ export interface TraineeDetail {
|
||||
activePlan: { id: string; title: string; startDate: string } | null;
|
||||
progress: { completed: number; total: number; percent: number } | null;
|
||||
killstreak: number;
|
||||
nextTraining: { dayId: string; date: string; exercises: { name: string; muscle: string }[] } | null;
|
||||
nextTraining: {
|
||||
dayId: string;
|
||||
date: string;
|
||||
exercises: { name: string; muscle: string }[];
|
||||
} | null;
|
||||
extra: { sets: number } | null;
|
||||
missing: { sets: number } | null;
|
||||
lastSessionAt: string | null;
|
||||
@@ -535,7 +566,14 @@ export interface DayMoveEntry {
|
||||
export interface Invitation {
|
||||
id: string;
|
||||
direction: 'sent' | 'received';
|
||||
other: { id: string; firstName: string | null; lastName: string | null; nickname: string | null; email: string; phone: string | null } | null;
|
||||
other: {
|
||||
id: string;
|
||||
firstName: string | null;
|
||||
lastName: string | null;
|
||||
nickname: string | null;
|
||||
email: string;
|
||||
phone: string | null;
|
||||
} | null;
|
||||
invitedAt: string;
|
||||
expiresAt: string;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user