Skip to content

Commit 6c1c03e

Browse files
authored
UI fixes (#445)
* fix: improve timeline input , ui improvement and fixes for participation tab * fix: implement 2fa for email and password login * fix: fix conflict
1 parent fb0c8c5 commit 6c1c03e

1 file changed

Lines changed: 41 additions & 4 deletions

File tree

components/profile/update/Settings.tsx

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
updateUserSettings,
1919
UserAppearance,
2020
UserNotifications,
21+
UserPreferences,
2122
UserPrivacy,
2223
UserSettings,
2324
} from '@/lib/api/auth';
@@ -75,6 +76,15 @@ interface SettingsProps {
7576
const Settings = ({ visibleSections }: SettingsProps) => {
7677
const [isLoading, setIsLoading] = useState(true);
7778
const [isSaving, setIsSaving] = useState(false);
79+
80+
const sections = visibleSections || [
81+
'notifications',
82+
'privacy',
83+
'appearance',
84+
'preferences',
85+
];
86+
const showAllSections = !visibleSections || visibleSections.length === 0;
87+
7888
const [settings, setSettings] = useState<UserSettings>({
7989
notifications: {
8090
emailNotifications: true,
@@ -221,6 +231,21 @@ const Settings = ({ visibleSections }: SettingsProps) => {
221231
}
222232
};
223233

234+
const onSubmitPreferences = async (data: UserPreferences) => {
235+
setIsSaving(true);
236+
try {
237+
await updateUserSettings({
238+
preferences: data,
239+
});
240+
toast.success('Preferences updated successfully');
241+
} catch {
242+
toast.error('Failed to update preferences');
243+
} finally {
244+
loadSettings();
245+
setIsSaving(false);
246+
}
247+
};
248+
224249
if (isLoading) {
225250
return (
226251
<div className='flex min-h-96 items-center justify-center'>
@@ -243,7 +268,7 @@ const Settings = ({ visibleSections }: SettingsProps) => {
243268
<Form {...form}>
244269
<form onSubmit={form.handleSubmit(onSubmit)} className='space-y-6'>
245270
{/* Notifications */}
246-
{(!visibleSections || visibleSections.includes('notifications')) && (
271+
{sections.includes('notifications') && (
247272
<Card className='rounded-xl border border-zinc-800 bg-zinc-900/30 p-4'>
248273
<div className='mb-4 flex items-center gap-3'>
249274
<Bell className='h-5 w-5 text-zinc-400' />
@@ -319,7 +344,7 @@ const Settings = ({ visibleSections }: SettingsProps) => {
319344
)}
320345

321346
{/* Privacy */}
322-
{(!visibleSections || visibleSections.includes('privacy')) && (
347+
{sections.includes('privacy') && (
323348
<Card className='rounded-xl border border-zinc-800 bg-zinc-900/30 p-4'>
324349
<div className='mb-4 flex items-center gap-3'>
325350
<Shield className='h-5 w-5 text-zinc-400' />
@@ -670,7 +695,13 @@ const Settings = ({ visibleSections }: SettingsProps) => {
670695
<FormItem>
671696
<FormLabel className='text-zinc-300'>Language</FormLabel>
672697
<Select
673-
onValueChange={field.onChange}
698+
onValueChange={async (value: string) => {
699+
field.onChange(value);
700+
await onSubmitPreferences({
701+
...form.getValues('preferences'),
702+
language: value,
703+
});
704+
}}
674705
value={field.value || undefined}
675706
>
676707
<FormControl>
@@ -724,7 +755,13 @@ const Settings = ({ visibleSections }: SettingsProps) => {
724755
<FormItem>
725756
<FormLabel className='text-zinc-300'>Timezone</FormLabel>
726757
<Select
727-
onValueChange={field.onChange}
758+
onValueChange={async (value: string) => {
759+
field.onChange(value);
760+
await onSubmitPreferences({
761+
...form.getValues('preferences'),
762+
timezone: value,
763+
});
764+
}}
728765
defaultValue={field.value}
729766
>
730767
<FormControl>

0 commit comments

Comments
 (0)