Profil: modernizacja podstrony danych osobowych (kafelki z ikonami, tone'owane grupy miesni, kafelki social); bez zmian w edycji

This commit is contained in:
tisachi
2026-10-17 07:28:41 +02:00
parent 8199c3e2a3
commit 0b3eff584d

View File

@@ -1,7 +1,23 @@
import { useEffect, useRef, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { useQueryClient } from '@tanstack/react-query';
import { Check, Pencil, Plus, Search, Trash2 } from 'lucide-react';
import {
ArrowRight,
AtSign,
Cake,
Check,
Clock,
Link2,
Pencil,
Phone,
Plus,
Ruler,
Search,
Sparkles,
Trash2,
User,
type LucideIcon,
} from 'lucide-react';
import { updateProfile, useFocusAreas, useFocusChain, useMe } from '../../api/queries';
import type {
Availability,
@@ -15,7 +31,6 @@ import {
Button,
Card,
Field,
H3,
Input,
Loading,
Modal,
@@ -27,12 +42,14 @@ import {
} from '../../components/ui';
import { useToast } from '../../components/toast';
import { AvailabilityEditor } from '../../components/AvailabilityEditor';
import { SOCIAL_MEDIA_LABELS } from '../../lib/labels';
import { MUSCLE_COLORS, MUSCLE_NAMES, SOCIAL_MEDIA_LABELS } from '../../lib/labels';
import {
emptyAvailability,
formatAvailability,
formatAvailabilityParts,
normalizeAvailability,
} from '../../lib/availability';
import { displayName } from '../../lib/format';
import { Avatar } from '../../components/Avatar';
import { useTopbar } from '../../topbar';
type MuscleField = 'developMuscles' | 'canDoMuscles' | 'difficultMuscles' | 'avoidMuscles';
@@ -43,6 +60,9 @@ const MUSCLE_TONES = {
active: 'bg-accent/15 text-accent-text border-accent/40',
badge: 'green',
text: 'text-accent-text',
/* podświetlenie grupy w karcie ciągu (bg + border lewy + kolor tekstu) */
tint: 'border-accent/40 bg-accent/10',
dot: 'bg-accent',
label: 'Co rozwija',
chainPrefix: 'do rozwoju: ',
},
@@ -50,6 +70,8 @@ const MUSCLE_TONES = {
active: 'bg-info/15 text-info border-info/40',
badge: 'blue',
text: 'text-info',
tint: 'border-info/40 bg-info/10',
dot: 'bg-info',
label: 'Co potrafi',
chainPrefix: '',
},
@@ -57,6 +79,8 @@ const MUSCLE_TONES = {
active: 'bg-warn/15 text-warn border-warn/40',
badge: 'yellow',
text: 'text-warn',
tint: 'border-warn/40 bg-warn/10',
dot: 'bg-warn',
label: 'Co trudne',
chainPrefix: '',
},
@@ -64,6 +88,8 @@ const MUSCLE_TONES = {
active: 'bg-danger/15 text-danger border-danger/40',
badge: 'red',
text: 'text-danger',
tint: 'border-danger/40 bg-danger/10',
dot: 'bg-danger',
label: 'Co unikać',
chainPrefix: 'unikamy: ',
},
@@ -102,15 +128,79 @@ interface MuscleFormState {
avoidMuscles: string[];
}
function InfoRow({ label, value }: { label: string; value: string }) {
/* Płytka informacyjna: ikona w tonie akcentu + etykieta + wartość (spójna z
mini-statystykami przeglądu profilu). Puste wartości wyciszone. */
function InfoTile({
icon: Icon,
label,
value,
}: {
icon: LucideIcon;
label: string;
value: string;
}) {
const empty = value === '—';
return (
<div className="flex items-baseline justify-between gap-4 px-2 py-2.5">
<span className="shrink-0 text-[0.9rem] text-dim">{label}</span>
<span className="min-w-0 truncate text-right text-[0.95rem] font-semibold">{value}</span>
<div className="flex items-center gap-3 rounded-[10px] border border-line bg-input/40 px-3 py-2.5">
<span className="grid h-9 w-9 shrink-0 place-items-center rounded-[10px] bg-accent/10 text-accent-text">
<Icon className="h-4.5 w-4.5" />
</span>
<div className="min-w-0">
<div className="text-[11px] font-bold uppercase tracking-[0.1em] text-dim">{label}</div>
<div className={`truncate text-[0.95rem] font-semibold ${empty ? 'text-dim' : ''}`.trim()}>
{value}
</div>
</div>
</div>
);
}
/* Płytki link społecznościowy: markowa kropka z inicjałem + nazwa + adres + strzałka. */
const SOCIAL_BRAND: Record<SocialMediaPlatform, { color: string; initial: string }> = {
INSTAGRAM: { color: 'linear-gradient(150deg,#f09433,#dc2743,#bc1888)', initial: 'i' },
TIKTOK: { color: 'linear-gradient(150deg,#25f4ee,#000 60%,#fe2c55)', initial: 'T' },
YOUTUBE: { color: 'linear-gradient(150deg,#ff5b4a,#c4302b)', initial: 'Y' },
FACEBOOK: { color: 'linear-gradient(150deg,#5b8def,#1877f2)', initial: 'f' },
X: { color: 'linear-gradient(150deg,#6b7280,#111)', initial: 'X' },
OTHER: { color: 'linear-gradient(150deg,#8fa3b8,#5f7183)', initial: '·' },
};
function hostOf(url: string): string {
try {
return new URL(url).hostname.replace(/^www\./, '');
} catch {
return url;
}
}
function SocialTile({ entry }: { entry: SocialMediaEntry }) {
const label =
entry.platform === 'OTHER' ? entry.label || 'Inne' : SOCIAL_MEDIA_LABELS[entry.platform];
const brand = SOCIAL_BRAND[entry.platform];
return (
<a
href={entry.url}
target="_blank"
rel="noopener noreferrer"
aria-label={label}
className="group flex items-center gap-3 rounded-xl border border-line bg-input/40 px-3.5 py-3 transition-colors hover:border-accent/45 hover:bg-accent/[0.06]"
>
<span
aria-hidden="true"
className="grid h-9 w-9 shrink-0 place-items-center rounded-full text-[0.85rem] font-extrabold text-white shadow-[inset_0_1px_0_rgb(255_255_255/0.25)]"
style={{ background: brand.color }}
>
{brand.initial}
</span>
<span className="min-w-0 flex-1">
<span className="block truncate text-[0.95rem] font-semibold">{label}</span>
<span className="block truncate text-[0.8125rem] text-dim">{hostOf(entry.url)}</span>
</span>
<ArrowRight className="h-4 w-4 shrink-0 text-dim transition-transform group-hover:translate-x-0.5 group-hover:text-accent-text" />
</a>
);
}
function MuscleChips({
areas,
selected,
@@ -219,33 +309,66 @@ function SocialMediaEditor({
);
}
/* Ciąg przyczynowo-skutkowy: 4 sekcje (rozwija / potrafi / trudne / unikać). */
/* Ciąg przyczynowo-skutkowy: 4 kafelki w tonie grupy (kolor spójny z „Priorytety
i wykluczenia”); puste tony wyciszone. Nazwy mięśni ujednolicone z resztą aplikacji. */
function FocusChainCard({ chain }: { chain: FocusChain | undefined }) {
return (
<Card>
<SectionHeader
title="Ciąg przyczynowo-skutkowy"
title={
<span className="flex items-center gap-2">
<Sparkles className="h-4.5 w-4.5 text-accent-text" />
Ciąg przyczynowo-skutkowy
</span>
}
description="Ćwiczenia z aktywnego planu w kontekście Twoich celów i wykluczeń."
/>
{chain ? (
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 sm:gap-5">
<div className="grid grid-cols-1 gap-3 sm:grid-cols-2">
{(Object.keys(MUSCLE_TONES) as MuscleTone[]).map((tone) => {
const entries = chain[tone] ?? [];
const t = MUSCLE_TONES[tone];
return (
<div key={tone}>
<H3 className={`mb-2 ${MUSCLE_TONES[tone].text}`}>{MUSCLE_TONES[tone].label}</H3>
<div
key={tone}
className={`rounded-xl border-l-[3px] border-y border-r px-4 py-3 ${
entries.length > 0 ? t.tint : 'border-line bg-input/40'
}`}
>
<div className="mb-2 flex items-center gap-2">
<span
className={`h-2 w-2 shrink-0 rounded-full ${
entries.length > 0 ? t.dot : 'bg-dim/40'
}`}
aria-hidden="true"
/>
<span
className={`text-[11px] font-bold uppercase tracking-[0.1em] ${
entries.length > 0 ? t.text : 'text-dim'
}`}
>
{t.label}
</span>
</div>
{entries.length === 0 ? (
<span className="text-[0.875rem] text-dim">—</span>
<span className="text-[0.875rem] text-dim">brak akcentów w planie</span>
) : (
<div className="flex flex-col gap-2.5">
<div className="space-y-3">
{entries.map((e) => (
<div key={e.muscle}>
<div className="text-[0.95rem] font-semibold">{e.name}</div>
<div className="mt-0.5 text-[0.875rem] text-dim">
<div className="flex items-center gap-2">
<Badge color={MUSCLE_COLORS[e.muscle] ?? 'gray'}>
{MUSCLE_NAMES[e.muscle] ?? e.name}
</Badge>
{(e.exercises ?? []).length > 0 && (
<span className="text-[0.75rem] font-bold tabular-nums text-dim">
{(e.exercises ?? []).length}
</span>
)}
</div>
<div className="mt-1 text-[0.875rem] text-dim">
{(e.exercises ?? []).length > 0
? `${MUSCLE_TONES[tone].chainPrefix}${(e.exercises ?? [])
.map((x) => x.name)
.join(', ')}`
? `${t.chainPrefix}${(e.exercises ?? []).map((x) => x.name).join(', ')}`
: 'brak w aktywnym planie'}
</div>
</div>
@@ -433,50 +556,98 @@ export default function ProfileInfo() {
);
}
const name = displayName(user ?? {});
const availabilityParts = formatAvailabilityParts(user?.availability);
return (
<>
<PageHeader
title="Dane osobowe"
leading={<Avatar name={name} size={40} />}
actions={<BackButton onClick={() => navigate('/profile')} />}
/>
{/* Karta 1: podstawowe dane */}
{/* Karta 1: podstawowe dane — siatka płytek z ikonami + dostępność jako chipy */}
<Card>
<SectionHeader title="Podstawowe dane" />
<div className="divide-y divide-line">
<InfoRow label="Imię" value={user?.firstName || '—'} />
<InfoRow label="Nazwisko" value={user?.lastName || '—'} />
<InfoRow label="Wiek" value={user?.age != null ? `${user.age} lat` : '—'} />
<InfoRow label="Wzrost" value={user?.heightCm != null ? `${user.heightCm} cm` : '—'} />
<InfoRow label="Telefon" value={user?.phone || '—'} />
<InfoRow label="Nick" value={user?.nickname || '—'} />
<InfoRow label="Dostępność" value={formatAvailability(user?.availability) || '—'} />
<div className="grid grid-cols-1 gap-2.5 sm:grid-cols-2">
<InfoTile icon={User} label="Imię" value={user?.firstName || '—'} />
<InfoTile icon={User} label="Nazwisko" value={user?.lastName || '—'} />
<InfoTile icon={Cake} label="Wiek" value={user?.age != null ? `${user.age} lat` : '—'} />
<InfoTile
icon={Ruler}
label="Wzrost"
value={user?.heightCm != null ? `${user.heightCm} cm` : '—'}
/>
<InfoTile icon={Phone} label="Telefon" value={user?.phone || '—'} />
<InfoTile icon={AtSign} label="Nick" value={user?.nickname || '—'} />
</div>
<div className="mt-3 rounded-[10px] border border-line bg-input/40 px-3.5 py-3">
<div className="mb-2 flex items-center gap-1.5 text-[11px] font-bold uppercase tracking-[0.1em] text-dim">
<Clock className="h-3.5 w-3.5" />
Dostępność
</div>
{availabilityParts.length > 0 ? (
<div className="flex flex-wrap gap-1.5">
{availabilityParts.map((p) => (
<Badge key={p} color="blue" className="font-semibold">
{p}
</Badge>
))}
</div>
) : (
<span className="text-[0.875rem] text-dim">Brak ustawionej dostępności</span>
)}
</div>
</Card>
{/* Karta 2: priorytety i wykluczenia (4 grupy mięśni) */}
{/* Karta 2: priorytety i wykluczenia — 4 kafelki w tonie grupy */}
<Card>
<SectionHeader title="Priorytety i wykluczenia" />
<div className="grid grid-cols-1 gap-x-4 gap-y-4 sm:grid-cols-2">
<div className="grid grid-cols-1 gap-2.5 sm:grid-cols-2">
{(Object.keys(MUSCLE_TONES) as MuscleTone[]).map((tone) => {
const musclesList = user?.[MUSCLE_FIELD_BY_TONE[tone]] ?? [];
const t = MUSCLE_TONES[tone];
return (
<div key={tone}>
<div className="mb-1.5 text-[11px] font-bold uppercase tracking-[0.1em] text-dim">
{MUSCLE_TONES[tone].label}
<div
key={tone}
className={`rounded-xl border-l-[3px] border-y border-r px-4 py-3 ${
musclesList.length > 0 ? t.tint : 'border-line bg-input/40'
}`}
>
<div className="mb-2 flex items-center gap-2">
<span
className={`h-2 w-2 shrink-0 rounded-full ${
musclesList.length > 0 ? t.dot : 'bg-dim/40'
}`}
aria-hidden="true"
/>
<span
className={`text-[11px] font-bold uppercase tracking-[0.1em] ${
musclesList.length > 0 ? t.text : 'text-dim'
}`}
>
{t.label}
</span>
{musclesList.length > 0 && (
<span className="ml-auto text-[11px] font-bold tabular-nums text-dim">
{musclesList.length}
</span>
)}
</div>
<div className="flex flex-wrap gap-1.5">
{musclesList.length > 0 ? (
musclesList.map((m) => (
<Badge
key={m}
color={MUSCLE_TONES[tone].badge as 'green' | 'blue' | 'yellow' | 'red'}
color={t.badge as 'green' | 'blue' | 'yellow' | 'red'}
className="bg-card/70"
>
{areaName(m)}
</Badge>
))
) : (
<span className="text-[0.875rem] text-dim">—</span>
<span className="text-[0.875rem] text-dim">nic nie dodano</span>
)}
</div>
</div>
@@ -485,26 +656,21 @@ export default function ProfileInfo() {
</div>
</Card>
{/* Karta 3: social media */}
{/* Karta 3: social media — kafelki linków z markową kropką i domeną */}
<Card>
<SectionHeader title="Social media" />
<div className="flex flex-wrap gap-1.5">
{(user?.socialMedia ?? []).length > 0 ? (
(user?.socialMedia ?? []).map((s, i) => (
<a
key={i}
href={s.url}
target="_blank"
rel="noopener noreferrer"
className="inline-flex items-center rounded-full border border-line px-3 py-1.5 text-[0.875rem] font-semibold text-accent-text hover:underline"
>
{s.platform === 'OTHER' ? s.label || 'Inne' : SOCIAL_MEDIA_LABELS[s.platform]}
</a>
))
) : (
<span className="text-[0.875rem] text-dim">—</span>
)}
</div>
{(user?.socialMedia ?? []).length > 0 ? (
<div className="grid grid-cols-1 gap-2.5 sm:grid-cols-2">
{(user?.socialMedia ?? []).map((s, i) => (
<SocialTile key={i} entry={s} />
))}
</div>
) : (
<div className="flex items-center gap-3 rounded-xl border border-dashed border-line bg-input/40 px-4 py-4 text-[0.875rem] text-dim">
<Link2 className="h-4 w-4 shrink-0" />
Brak dodanych profili.
</div>
)}
</Card>
<FocusChainCard chain={chain} />