website refactor
This commit is contained in:
64
apps/website/client-wrapper/ProfileSettingsPageClient.tsx
Normal file
64
apps/website/client-wrapper/ProfileSettingsPageClient.tsx
Normal file
@@ -0,0 +1,64 @@
|
||||
'use client';
|
||||
|
||||
import { InlineNotice } from '@/ui/InlineNotice';
|
||||
import { ProgressLine } from '@/ui/ProgressLine';
|
||||
import type { Result } from '@/lib/contracts/Result';
|
||||
import type { ProfileViewData } from '@/lib/view-data/ProfileViewData';
|
||||
import { ProfileSettingsTemplate } from '@/templates/ProfileSettingsTemplate';
|
||||
import { Box } from '@/ui/Box';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useState } from 'react';
|
||||
|
||||
interface ProfileSettingsPageClientProps {
|
||||
viewData: ProfileViewData;
|
||||
onSave: (updates: { bio?: string; country?: string }) => Promise<Result<void, string>>;
|
||||
}
|
||||
|
||||
export function ProfileSettingsPageClient({ viewData, onSave }: ProfileSettingsPageClientProps) {
|
||||
const router = useRouter();
|
||||
const [isSaving, setIsSaving] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
const [bio, setBio] = useState(viewData.driver.bio || '');
|
||||
const [country, setCountry] = useState(viewData.driver.countryCode);
|
||||
|
||||
const handleSave = async () => {
|
||||
setIsSaving(true);
|
||||
setError(null);
|
||||
try {
|
||||
const result = await onSave({ bio, country });
|
||||
if (result.isErr()) {
|
||||
setError(result.getError());
|
||||
} else {
|
||||
router.refresh();
|
||||
}
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Failed to save settings');
|
||||
} finally {
|
||||
setIsSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<ProgressLine isLoading={isSaving} />
|
||||
{error && (
|
||||
<Box position="fixed" top={4} right={4} zIndex={50} maxWidth="md">
|
||||
<InlineNotice
|
||||
variant="error"
|
||||
title="Update Failed"
|
||||
message={error}
|
||||
/>
|
||||
</Box>
|
||||
)}
|
||||
<ProfileSettingsTemplate
|
||||
viewData={viewData}
|
||||
bio={bio}
|
||||
country={country}
|
||||
onBioChange={setBio}
|
||||
onCountryChange={setCountry}
|
||||
onSave={handleSave}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user