oit says profile succesfully updated, yet when I reload nothing is saved
This commit is contained in:
@@ -7,7 +7,6 @@ import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { z } from 'zod';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { useToast } from '@/hooks/use-toast';
|
||||
import {
|
||||
Card,
|
||||
@@ -17,6 +16,7 @@ import {
|
||||
CardDescription,
|
||||
} from '@/components/ui/card';
|
||||
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form';
|
||||
import { getUser, updateUser } from '@/lib/actions/user';
|
||||
|
||||
const formSchema = z.object({
|
||||
name: z.string().min(1, 'Name is required'),
|
||||
@@ -26,27 +26,6 @@ const formSchema = z.object({
|
||||
|
||||
type UserFormValues = z.infer<typeof formSchema>;
|
||||
|
||||
// Mock server actions
|
||||
async function getUser() {
|
||||
console.log("Mocking getUser");
|
||||
return { id: '1', name: 'Admin User', email: 'admin@example.com' };
|
||||
}
|
||||
|
||||
async function updateUser(data: UserFormValues) {
|
||||
console.log("Mocking updateUser with data:", data);
|
||||
// Simulate API call
|
||||
return new Promise<{ success: boolean; message: string }>((resolve) => {
|
||||
setTimeout(() => {
|
||||
if (data.email.includes('fail')) {
|
||||
resolve({ success: false, message: 'This email is already taken.' });
|
||||
} else {
|
||||
resolve({ success: true, message: 'Profile updated successfully!' });
|
||||
}
|
||||
}, 1000);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
export default function UserProfilePage() {
|
||||
const { toast } = useToast();
|
||||
const form = useForm<UserFormValues>({
|
||||
@@ -68,6 +47,8 @@ export default function UserProfilePage() {
|
||||
email: user.email,
|
||||
password: '',
|
||||
});
|
||||
} else {
|
||||
throw new Error('User not found.');
|
||||
}
|
||||
} catch (error) {
|
||||
toast({
|
||||
|
||||
Reference in New Issue
Block a user