diff --git a/app/src/api/queries.ts b/app/src/api/queries.ts index 9f1d0d5..79f07bb 100644 --- a/app/src/api/queries.ts +++ b/app/src/api/queries.ts @@ -368,6 +368,43 @@ export function usePlan(id: string) { }); } +/** Plany jawnie udostępnione zalogowanemu (read-only). */ +export function useSharedWithMe() { + return useQuery({ + queryKey: ['plans', 'shared-with-me'], + queryFn: () => api<{ plans: Plan[] }>('/plans/shared-with-me'), + }); +} + +/** Moi trenerzy (ACTIVE coachings, gdzie ja jestem podopiecznym). */ +export function useMyTrainers() { + return useQuery({ + queryKey: ['me', 'trainers'], + queryFn: () => + api<{ + trainers: { + id: string; + firstName: string | null; + lastName: string | null; + nickname: string | null; + }[]; + }>('/me/trainers'), + }); +} + +/** Udostępnienie planu użytkownikowi z AKTYWNYM coachingiem (właściciel). */ +export function sharePlan(planId: string, userId: string) { + return api<{ share: { id: string } }>(`/plans/${planId}/share`, { + method: 'POST', + body: { userId }, + }); +} + +/** Cofnięcie udostępnienia (właściciel). */ +export function unsharePlan(planId: string, userId: string) { + return api(`/plans/${planId}/share/${userId}`, { method: 'DELETE' }); +} + export interface PlanSetInput { index: number; reps?: number | null; @@ -412,7 +449,7 @@ export function createPlan(body: PlanBody) { return api<{ plan: { id: string } }>('/plans', { method: 'POST', body }); } -export function updatePlan(id: string, body: Omit) { +export function updatePlan(id: string, body: PlanBody) { return api(`/plans/${id}`, { method: 'PATCH', body }); } @@ -726,11 +763,7 @@ export function createTraineePlan(userId: string, body: PlanBody) { }); } -export function updateTraineePlan( - userId: string, - planId: string, - body: Omit, -) { +export function updateTraineePlan(userId: string, planId: string, body: PlanBody) { return api(`/trainer/trainees/${userId}/plans/${planId}`, { method: 'PATCH', body }); } diff --git a/app/src/components/ui/week-picker.tsx b/app/src/components/ui/week-picker.tsx index b1581e2..3754a58 100644 --- a/app/src/components/ui/week-picker.tsx +++ b/app/src/components/ui/week-picker.tsx @@ -85,7 +85,7 @@ export function WeekPicker({ const selMondayKey = value ? localDayKey(mondayOf(parseIsoLocal(value))) : null; return ( -
+