im afraid we cant move forward if you are not able to resolve the simple
This commit is contained in:
@@ -16,8 +16,9 @@ import {
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { useToast } from "@/hooks/use-toast";
|
||||
import { useEffect, useTransition } from "react";
|
||||
import { useEffect, useState, useTransition } from "react";
|
||||
import { getUser, updateUser } from "@/lib/actions/user";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
|
||||
const userProfileSchema = z.object({
|
||||
name: z.string().min(1, "Name is required"),
|
||||
@@ -34,6 +35,7 @@ type UserProfileFormValues = z.infer<typeof userProfileSchema>;
|
||||
export default function UserProfilePage() {
|
||||
const { toast } = useToast();
|
||||
const [isSaving, startSavingTransition] = useTransition();
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
|
||||
const {
|
||||
register,
|
||||
@@ -52,6 +54,7 @@ export default function UserProfilePage() {
|
||||
|
||||
useEffect(() => {
|
||||
const fetchUser = async () => {
|
||||
setIsLoading(true);
|
||||
const user = await getUser();
|
||||
if (user) {
|
||||
reset({
|
||||
@@ -60,10 +63,17 @@ export default function UserProfilePage() {
|
||||
password: "",
|
||||
confirmPassword: ""
|
||||
});
|
||||
} else {
|
||||
toast({
|
||||
title: "Error",
|
||||
description: "Could not load user profile.",
|
||||
variant: "destructive",
|
||||
});
|
||||
}
|
||||
setIsLoading(false);
|
||||
};
|
||||
fetchUser();
|
||||
}, [reset]);
|
||||
}, [reset, toast]);
|
||||
|
||||
const onSubmit: SubmitHandler<UserProfileFormValues> = (data) => {
|
||||
startSavingTransition(async () => {
|
||||
@@ -99,16 +109,31 @@ export default function UserProfilePage() {
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="grid gap-6">
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="name">Name</Label>
|
||||
<Input id="name" {...register("name")} />
|
||||
{errors.name && <p className="text-sm text-destructive">{errors.name.message}</p>}
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="email">Email</Label>
|
||||
<Input id="email" type="email" {...register("email")} />
|
||||
{errors.email && <p className="text-sm text-destructive">{errors.email.message}</p>}
|
||||
</div>
|
||||
{isLoading ? (
|
||||
<>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="name">Name</Label>
|
||||
<Skeleton className="h-10 w-full" />
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="email">Email</Label>
|
||||
<Skeleton className="h-10 w-full" />
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="name">Name</Label>
|
||||
<Input id="name" {...register("name")} />
|
||||
{errors.name && <p className="text-sm text-destructive">{errors.name.message}</p>}
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="email">Email</Label>
|
||||
<Input id="email" type="email" {...register("email")} />
|
||||
{errors.email && <p className="text-sm text-destructive">{errors.email.message}</p>}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="password">New Password</Label>
|
||||
<Input id="password" type="password" {...register("password")} />
|
||||
@@ -121,7 +146,7 @@ export default function UserProfilePage() {
|
||||
</div>
|
||||
</CardContent>
|
||||
<CardFooter className="flex justify-end">
|
||||
<Button type="submit" disabled={isSaving || !isDirty}>
|
||||
<Button type="submit" disabled={isSaving || !isDirty || isLoading}>
|
||||
{isSaving ? 'Saving...' : 'Save Changes'}
|
||||
</Button>
|
||||
</CardFooter>
|
||||
|
||||
Reference in New Issue
Block a user