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:
@@ -24,6 +24,7 @@ import {
|
||||
useActiveSession,
|
||||
useConversations,
|
||||
useFeedUnreadCount,
|
||||
useGymContactInbox,
|
||||
useGymInvitations,
|
||||
useInvitations,
|
||||
useIsTrainer,
|
||||
@@ -200,14 +201,14 @@ export default function Layout() {
|
||||
const { data: invitations } = useInvitations();
|
||||
const { data: gymInvitations } = useGymInvitations();
|
||||
const { data: conversations } = useConversations();
|
||||
const { data: gymContactData } = useGymContactInbox();
|
||||
// Liczba oczekujących zaproszeń: coaching (trener) + do prywatnych siłowni.
|
||||
const pendingInvitations =
|
||||
(invitations?.invitations ?? []).length + (gymInvitations?.invitations ?? []).length;
|
||||
// Nieprzeczytane wiadomości w komunikatorze (suma per rozmowa).
|
||||
const unreadMessages = (conversations?.conversations ?? []).reduce(
|
||||
(n, c) => n + c.unreadCount,
|
||||
0,
|
||||
);
|
||||
// Nieprzeczytane: komunikator coachingowy + wątki kontaktu z właścicielami siłowni.
|
||||
const unreadMessages =
|
||||
(conversations?.conversations ?? []).reduce((n, c) => n + c.unreadCount, 0) +
|
||||
(gymContactData?.conversations ?? []).reduce((n, c) => n + c.unreadCount, 0);
|
||||
// Nieprzeczytane aktualności (powiadomienia osobiste + ogłoszenia siłowni).
|
||||
const { data: feedUnread } = useFeedUnreadCount();
|
||||
const unreadFeed = feedUnread?.unreadCount ?? 0;
|
||||
|
||||
@@ -1,8 +1,15 @@
|
||||
import { useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
import { sendGymInvitation, useGymInviteeSearch } from '../../api/queries';
|
||||
import { Button, ErrorText, Field, Input, Loading, Modal } from '../ui';
|
||||
import {
|
||||
sendGymInvitation,
|
||||
useGymInvitations,
|
||||
useGymInviteeSearch,
|
||||
withdrawGymInvitation,
|
||||
} from '../../api/queries';
|
||||
import type { GymInvitation } from '../../api/types';
|
||||
import { Avatar } from '../Avatar';
|
||||
import { Button, ConfirmDialog, ErrorText, Field, Input, ListRow, Loading, Modal } from '../ui';
|
||||
import { useToast } from '../toast';
|
||||
|
||||
/** Wyszukajka imię + nazwisko → „Zaproś” per user (właściciel prywatnej VIRTUAL). */
|
||||
@@ -94,6 +101,86 @@ export default function InviteGymModal({
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
<SentInvitationsList gymId={gym.id} />
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
/* Wysłane zaproszenia (dawna karta w treści detailu — przeniesiona do modala,
|
||||
1 kontrolka = 1 miejsce): lista + „Wycofaj” z potwierdzeniem. */
|
||||
function SentInvitationsList({ gymId }: { gymId: string }) {
|
||||
const queryClient = useQueryClient();
|
||||
const { push } = useToast();
|
||||
const { t } = useTranslation('gyms');
|
||||
const { data } = useGymInvitations();
|
||||
const sent = (data?.invitations ?? []).filter(
|
||||
(i) => i.direction === 'sent' && i.gym.id === gymId,
|
||||
);
|
||||
const [toWithdraw, setToWithdraw] = useState<GymInvitation | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
const withdraw = async () => {
|
||||
if (!toWithdraw) return;
|
||||
setBusy(true);
|
||||
try {
|
||||
await withdrawGymInvitation(toWithdraw.id);
|
||||
await queryClient.invalidateQueries({ queryKey: ['gym-invitations'] });
|
||||
push(t('invites.toastWithdrawn'), 'success');
|
||||
setToWithdraw(null);
|
||||
} catch (e) {
|
||||
push((e as Error).message, 'error');
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
if (sent.length === 0) return null;
|
||||
const name = toWithdraw
|
||||
? [toWithdraw.user?.firstName, toWithdraw.user?.lastName].filter(Boolean).join(' ') ||
|
||||
toWithdraw.user?.email ||
|
||||
'—'
|
||||
: '';
|
||||
|
||||
return (
|
||||
<div className="mt-4 border-t border-line pt-4">
|
||||
<div className="mb-1.5 text-[11px] font-bold uppercase tracking-[0.1em] text-dim">
|
||||
{t('invite.sentTitle')}
|
||||
</div>
|
||||
<div className="divide-y divide-line">
|
||||
{sent.map((inv) => {
|
||||
const invName =
|
||||
[inv.user?.firstName, inv.user?.lastName].filter(Boolean).join(' ') ||
|
||||
inv.user?.email ||
|
||||
'—';
|
||||
return (
|
||||
<ListRow
|
||||
key={inv.id}
|
||||
title={
|
||||
<span className="flex items-center gap-2.5">
|
||||
<Avatar name={invName} size={28} />
|
||||
{invName}
|
||||
</span>
|
||||
}
|
||||
actions={
|
||||
<Button variant="ghost" size="sm" type="button" onClick={() => setToWithdraw(inv)}>
|
||||
{t('invites.withdraw')}
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
<ConfirmDialog
|
||||
open={toWithdraw != null}
|
||||
onClose={() => setToWithdraw(null)}
|
||||
onConfirm={() => void withdraw()}
|
||||
title={t('invites.withdraw')}
|
||||
description={t('invites.confirmWithdraw', { name })}
|
||||
confirmLabel={t('invites.withdraw')}
|
||||
danger
|
||||
busy={busy}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user