patterns, skeleton loading, photo selection/bulk actions with shared‑element transitions, notification detail sheet,
offline banner, maskable manifest icons, and route prefetching.
Key changes
- Navigation/shell: press feedback on all header actions, glassy sticky header and tab bar, safer bottom spacing
(resources/js/admin/mobile/components/MobileShell.tsx, resources/js/admin/mobile/components/BottomNav.tsx).
- Forms + lists: shared mobile form controls, list‑style rows in settings/profile, consistent inputs across core
flows (resources/js/admin/mobile/components/FormControls.tsx, resources/js/admin/mobile/SettingsPage.tsx,
resources/js/admin/mobile/ProfilePage.tsx, resources/js/admin/mobile/EventFormPage.tsx, resources/js/admin/mobile/
EventMembersPage.tsx, resources/js/admin/mobile/EventTasksPage.tsx, resources/js/admin/mobile/
EventGuestNotificationsPage.tsx, resources/js/admin/mobile/NotificationsPage.tsx, resources/js/admin/mobile/
EventPhotosPage.tsx, resources/js/admin/mobile/EventsPage.tsx).
- Media workflows: shared‑element photo transitions, selection mode + bulk actions bar (resources/js/admin/mobile/
EventPhotosPage.tsx).
- Loading UX: shimmering skeletons (resources/css/app.css, resources/js/admin/mobile/components/Primitives.tsx).
- PWA polish + perf: maskable icons, offline banner hook, and route prefetch (public/manifest.json, resources/js/
admin/mobile/hooks/useOnlineStatus.tsx, resources/js/admin/mobile/prefetch.ts, resources/js/admin/main.tsx).
196 lines
7.1 KiB
TypeScript
196 lines
7.1 KiB
TypeScript
import React from 'react';
|
|
import { useNavigate } from 'react-router-dom';
|
|
import { useTranslation } from 'react-i18next';
|
|
import { Shield, Bell, User } from 'lucide-react';
|
|
import { YStack, XStack } from '@tamagui/stacks';
|
|
import { YGroup } from '@tamagui/group';
|
|
import { ListItem } from '@tamagui/list-item';
|
|
import { SizableText as Text } from '@tamagui/text';
|
|
import { Switch } from '@tamagui/switch';
|
|
import { useTheme } from '@tamagui/core';
|
|
import { MobileShell } from './components/MobileShell';
|
|
import { MobileCard, CTAButton, PillBadge } from './components/Primitives';
|
|
import { useAuth } from '../auth/context';
|
|
import {
|
|
getNotificationPreferences,
|
|
updateNotificationPreferences,
|
|
NotificationPreferences,
|
|
} from '../api';
|
|
import { getApiErrorMessage } from '../lib/apiError';
|
|
import { adminPath } from '../constants';
|
|
|
|
type PreferenceKey = keyof NotificationPreferences;
|
|
|
|
const AVAILABLE_PREFS: PreferenceKey[] = [
|
|
'photo_thresholds',
|
|
'photo_limits',
|
|
'guest_thresholds',
|
|
'guest_limits',
|
|
'gallery_warnings',
|
|
'gallery_expired',
|
|
'event_thresholds',
|
|
'event_limits',
|
|
'package_expiring',
|
|
'package_expired',
|
|
];
|
|
|
|
export default function MobileSettingsPage() {
|
|
const { t } = useTranslation('management');
|
|
const navigate = useNavigate();
|
|
const { user, logout } = useAuth();
|
|
const theme = useTheme();
|
|
const text = String(theme.color?.val ?? '#0f172a');
|
|
const muted = String(theme.gray?.val ?? '#6b7280');
|
|
const border = String(theme.borderColor?.val ?? '#e5e7eb');
|
|
const [preferences, setPreferences] = React.useState<NotificationPreferences>({});
|
|
const [defaults, setDefaults] = React.useState<NotificationPreferences>({});
|
|
const [loading, setLoading] = React.useState(true);
|
|
const [saving, setSaving] = React.useState(false);
|
|
const [error, setError] = React.useState<string | null>(null);
|
|
|
|
React.useEffect(() => {
|
|
(async () => {
|
|
setLoading(true);
|
|
try {
|
|
const result = await getNotificationPreferences();
|
|
const defaultsMerged: NotificationPreferences = result.defaults ?? {};
|
|
const prefs = { ...defaultsMerged, ...(result.preferences ?? {}) };
|
|
AVAILABLE_PREFS.forEach((key) => {
|
|
if (prefs[key] === undefined) {
|
|
prefs[key] = defaultsMerged[key] ?? false;
|
|
}
|
|
});
|
|
setPreferences(prefs);
|
|
setDefaults(defaultsMerged);
|
|
setError(null);
|
|
} catch (err) {
|
|
setError(getApiErrorMessage(err, t('settings.notifications.errorLoad', 'Benachrichtigungen konnten nicht geladen werden.')));
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
})();
|
|
}, [t]);
|
|
|
|
const togglePref = (key: PreferenceKey) => {
|
|
setPreferences((prev) => ({
|
|
...prev,
|
|
[key]: !prev[key],
|
|
}));
|
|
};
|
|
|
|
const handleSave = async () => {
|
|
setSaving(true);
|
|
try {
|
|
const payload: NotificationPreferences = {};
|
|
AVAILABLE_PREFS.forEach((key) => {
|
|
payload[key] = Boolean(preferences[key]);
|
|
});
|
|
await updateNotificationPreferences(payload);
|
|
setError(null);
|
|
} catch (err) {
|
|
setError(getApiErrorMessage(err, t('settings.notifications.errorSave', 'Speichern fehlgeschlagen')));
|
|
} finally {
|
|
setSaving(false);
|
|
}
|
|
};
|
|
|
|
const handleReset = () => {
|
|
setPreferences(defaults);
|
|
};
|
|
|
|
return (
|
|
<MobileShell activeTab="profile" title={t('mobileSettings.title', 'Settings')} onBack={() => navigate(-1)}>
|
|
{error ? (
|
|
<MobileCard>
|
|
<Text fontWeight="700" color="#b91c1c">
|
|
{error}
|
|
</Text>
|
|
</MobileCard>
|
|
) : null}
|
|
|
|
<MobileCard space="$3">
|
|
<XStack alignItems="center" space="$2">
|
|
<Shield size={18} color={text} />
|
|
<Text fontSize="$md" fontWeight="800" color={text}>
|
|
{t('mobileSettings.accountTitle', 'Account')}
|
|
</Text>
|
|
</XStack>
|
|
<Text fontSize="$sm" color={muted}>
|
|
{user?.name ?? user?.email ?? t('settings.session.unknown', 'Benutzer')}
|
|
</Text>
|
|
{user?.tenant_id ? (
|
|
<PillBadge tone="muted">{t('mobileSettings.tenantBadge', 'Tenant #{{id}}', { id: user.tenant_id })}</PillBadge>
|
|
) : null}
|
|
<XStack space="$2">
|
|
<CTAButton label={t('settings.profile.actions.openProfile', 'Profil bearbeiten')} onPress={() => navigate(adminPath('/mobile/profile'))} />
|
|
<CTAButton label={t('settings.session.logout', 'Abmelden')} tone="ghost" onPress={() => logout({ redirect: adminPath('/logout') })} />
|
|
</XStack>
|
|
</MobileCard>
|
|
|
|
<MobileCard space="$3">
|
|
<XStack alignItems="center" space="$2">
|
|
<Bell size={18} color={text} />
|
|
<Text fontSize="$md" fontWeight="800" color={text}>
|
|
{t('mobileSettings.notificationsTitle', 'Notifications')}
|
|
</Text>
|
|
</XStack>
|
|
{loading ? (
|
|
<Text fontSize="$sm" color={muted}>
|
|
{t('mobileSettings.notificationsLoading', 'Loading settings ...')}
|
|
</Text>
|
|
) : (
|
|
<YGroup borderRadius="$4" borderWidth={1} borderColor={border} overflow="hidden">
|
|
{AVAILABLE_PREFS.map((key, index) => (
|
|
<YGroup.Item key={key} bordered={index < AVAILABLE_PREFS.length - 1}>
|
|
<ListItem
|
|
hoverTheme
|
|
pressTheme
|
|
paddingVertical="$2"
|
|
paddingHorizontal="$3"
|
|
title={
|
|
<Text fontSize="$sm" color={text} fontWeight="700">
|
|
{t(`settings.notifications.keys.${key}.label`, key)}
|
|
</Text>
|
|
}
|
|
subTitle={
|
|
<Text fontSize="$xs" color={muted}>
|
|
{t(`settings.notifications.keys.${key}.description`, '')}
|
|
</Text>
|
|
}
|
|
iconAfter={
|
|
<Switch
|
|
size="$4"
|
|
checked={Boolean(preferences[key])}
|
|
onCheckedChange={() => togglePref(key)}
|
|
aria-label={t(`settings.notifications.keys.${key}.label`, key)}
|
|
>
|
|
<Switch.Thumb />
|
|
</Switch>
|
|
}
|
|
/>
|
|
</YGroup.Item>
|
|
))}
|
|
</YGroup>
|
|
)}
|
|
<XStack space="$2">
|
|
<CTAButton label={saving ? t('common.processing', '...') : t('settings.notifications.actions.save', 'Speichern')} onPress={() => handleSave()} />
|
|
<CTAButton label={t('common.reset', 'Reset')} tone="ghost" onPress={() => handleReset()} />
|
|
</XStack>
|
|
</MobileCard>
|
|
|
|
<MobileCard space="$3">
|
|
<XStack alignItems="center" space="$2">
|
|
<User size={18} color={text} />
|
|
<Text fontSize="$md" fontWeight="800" color={text}>
|
|
{t('settings.appearance.title', 'Darstellung')}
|
|
</Text>
|
|
</XStack>
|
|
<Text fontSize="$sm" color={muted}>
|
|
{t('settings.appearance.description', 'Schalte Dark-Mode oder passe Branding im Admin an.')}
|
|
</Text>
|
|
<CTAButton label={t('settings.appearance.title', 'Darstellung & Branding')} tone="ghost" onPress={() => navigate(adminPath('/settings'))} />
|
|
</MobileCard>
|
|
</MobileShell>
|
|
);
|
|
}
|