From 8049c4bc47c5ffa43c58103016f1b74aa3e926f4 Mon Sep 17 00:00:00 2001 From: tisachi Date: Sun, 13 Sep 2026 02:28:11 +0200 Subject: [PATCH] Plany: edytor - akcje inline od md+ i pojedyncze Wstecz (smartBack), tydzien startu w edycji (zapis = aktualizacja + aktywacja), kalendarz pelna szerokosc --- app/src/api/queries.ts | 45 ++++++++++++++--- app/src/components/ui/week-picker.tsx | 2 +- app/src/pages/plans/PlanEditor.tsx | 34 ++++++------- .../pages/plans/plan-editor/PlanMetaForm.tsx | 48 +++++++------------ .../plans/plan-editor/usePlanEditorState.ts | 6 ++- app/src/topbar/GroupButton.tsx | 22 +++++++-- app/src/topbar/Topbar.tsx | 1 + app/src/topbar/types.ts | 6 +++ app/test/PlanEditor.test.tsx | 25 +++++++++- 9 files changed, 128 insertions(+), 61 deletions(-) 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 ( -
+