App: kontakt z wlascicielami sirowni (podstrona /gyms/:id/contact + sekcja w komunikatorze + badge) i statystyki wlasciciela REAL (kafelek + podstrona /gyms/:id/stats); karty VIRTUAL czysto nawigacyjne, akcje dolacz/ocena/zarzadzaj przeniesione do menu detalu (grupa Zarzadzaj zwinieta na lg+)

This commit is contained in:
tisachi
2026-10-23 22:36:12 +02:00
parent 784a94b15f
commit 3dc36bb1fa
28 changed files with 2099 additions and 463 deletions

View File

@@ -35,8 +35,13 @@ import type {
CircumferenceSeries,
Invitation,
GymClaim,
GymContactMessage,
GymContactThread,
GymContactThreadListItem,
GymContactView,
GymInvitation,
GymKind,
GymStatsOverview,
VirtualGym,
Trainee,
TraineeDetail,
@@ -159,6 +164,80 @@ export function useGymEquipmentUsage(gymId: string | undefined, rangeDays: numbe
});
}
// ---------- kontakt członek ↔ właściciele siłowni ----------
/** Widok kontaktu per siłownia: member → własny wątek; owner/admin → lista wątków gyma. */
export function useGymContactView(gymId: string | undefined) {
return useQuery({
queryKey: ['gym-contact', 'view', gymId],
queryFn: () => api<GymContactView>(`/gyms/${gymId}/contact`),
enabled: !!gymId,
refetchInterval: 30_000,
});
}
/** Członek inicjuje/odpowiada we własnym wątku (upsert per [gymId,userId]). */
export function sendGymContactMessage(gymId: string, body: string) {
return api<{
conversation: {
id: string;
gymId: string;
userId: string;
createdAt: string;
updatedAt: string;
};
}>(`/gyms/${encodeURIComponent(gymId)}/contact/messages`, { method: 'POST', body: { body } });
}
/** Skrzynka właściciela: wątki we wszystkich gymach, gdzie caller ma rolę OWNER. */
export function useGymContactInbox() {
return useQuery({
queryKey: ['gym-contact', 'inbox'],
queryFn: () => api<{ conversations: GymContactThreadListItem[] }>('/gym-contact/conversations'),
refetchInterval: 30_000,
});
}
/** Pojedynczy wątek (read-mark po stronie API). */
export function useGymContactThread(conversationId: string) {
return useQuery({
queryKey: ['gym-contact', 'thread', conversationId],
queryFn: () =>
api<GymContactThread>(`/gym-contact/conversations/${encodeURIComponent(conversationId)}`),
enabled: !!conversationId,
refetchInterval: 30_000,
});
}
/** Odpowiedź uczestnika w wątku (właściciel/admin lub członek). */
export function sendGymContactReply(conversationId: string, body: string) {
return api<{ message: GymContactMessage }>(
`/gym-contact/conversations/${encodeURIComponent(conversationId)}/messages`,
{ method: 'POST', body: { body } },
);
}
/** Usunięcie własnej wiadomości (twardy delete, tylko autor). */
export function deleteGymContactMessage(messageId: string) {
return api(`/gym-contact/messages/${encodeURIComponent(messageId)}`, { method: 'DELETE' });
}
/**
* Statystyki właściciela (REAL): presence + członkowie + aktywność treningowa.
* `rangeDays`: 7/30/90, from liczony od teraz (jak mapa ciepła urządzeń).
*/
export function useGymStatsOverview(gymId: string | undefined, rangeDays: number) {
return useQuery({
queryKey: ['gym-stats-overview', gymId, rangeDays],
queryFn: () => {
const from = new Date(Date.now() - rangeDays * 86_400_000).toISOString();
return api<GymStatsOverview>(
`/gyms/${gymId}/stats/overview?from=${encodeURIComponent(from)}`,
);
},
enabled: !!gymId,
});
}
// ---------- bytność (check-in, live occupancy) ----------
/** Aktywna bytność zalogowanego — podstawa przycisków „Idę ćwiczyć / Wychodzę / Wciąż tu jestem". */
export function useActivePresence(refetchIntervalMs?: number) {

View File

@@ -158,6 +158,8 @@ export interface Gym {
coverPhoto: string | null;
/** Live „teraz: N" (aktywne bytności); null dla VIRTUAL (brak meldunków). */
currentOccupancy?: number | null;
/** Głos zalogowanego (publiczna VIRTUAL); null = nie głosował; brak dla REAL/prywatnych. */
myVote?: 'UP' | 'DOWN' | null;
}
/** Odpowiedź detalu siłowni (GET /gyms/:id): siłownia + galeria + role zalogowanego. */
@@ -294,6 +296,87 @@ export interface GymException {
availability: DayAvailability | null;
}
// ---------- kontakt członek ↔ właściciele siłowni ----------
export type GymContactRole = 'member' | 'owner' | 'admin';
export interface GymContactMessage {
id: string;
senderId: string;
senderName: string;
body: string;
createdAt: string;
}
export interface GymContactConversationInfo {
id: string;
gymId: string;
gymName: string;
/** Autor wątku (członek, który go zainicjował). */
userId: string;
memberName: string;
createdAt: string;
updatedAt: string;
}
/** Widok członka: własny wątek (lazily null) + strumień + canReply. */
export interface GymContactMemberView {
role: 'member';
conversation: GymContactConversationInfo | null;
messages: GymContactMessage[];
canReply: boolean;
}
export interface GymContactThreadListItem {
id: string;
gymId: string;
gymName: string;
userId: string;
counterpartName: string;
lastMessageBody: string | null;
lastMessageAt: string | null;
unreadCount: number;
}
/** Widok właściciela/admina siłowni: lista wątków tego gyma. */
export interface GymContactManagerView {
role: 'owner' | 'admin';
threads: GymContactThreadListItem[];
}
export type GymContactView = GymContactMemberView | GymContactManagerView;
/** Pojedynczy wątek (GET /gym-contact/conversations/:id) — read-mark po stronie API. */
export interface GymContactThread {
role: GymContactRole;
conversation: GymContactConversationInfo;
messages: GymContactMessage[];
canReply: boolean;
}
// ---------- statystyki właściciela (GET /gyms/:id/stats/overview, REAL) ----------
export interface GymStatsOverview {
gym: { id: string; name: string; kind: GymKind; capacity: number | null };
presence: {
visits: number;
visitsPerDay: number;
avgStayMinutes: number | null;
peak: number;
live: number;
heatmap: { day: number; hour: number; count: number }[];
};
members: {
total: number;
byRole: { OWNER: number; TRAINER: number; MEMBER: number };
newInRange: number;
};
activity: {
sessionsStarted: number;
sessionsCompleted: number;
sessionsAbandoned: number;
uniqueExercisers: number;
};
}
export interface Exercise {
id: string;
slug: string;