refactor(frontend): FollowButton useOptimistic + Server Action; edit-profile-form Server Action
This commit is contained in:
@@ -3,9 +3,8 @@
|
||||
import { useForm } from "react-hook-form";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { z } from "zod";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useAuth } from "@/hooks/use-auth";
|
||||
import { Me, UpdateProfileSchema, updateProfile } from "@/lib/api";
|
||||
import { Me, UpdateProfileSchema } from "@/lib/api";
|
||||
import { updateProfile } from "@/app/actions/profile";
|
||||
import { toast } from "sonner";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card, CardContent, CardFooter } from "@/components/ui/card";
|
||||
@@ -25,8 +24,6 @@ interface EditProfileFormProps {
|
||||
}
|
||||
|
||||
export function EditProfileForm({ currentUser }: EditProfileFormProps) {
|
||||
const router = useRouter();
|
||||
const { token } = useAuth();
|
||||
|
||||
const form = useForm<z.infer<typeof UpdateProfileSchema>>({
|
||||
resolver: zodResolver(UpdateProfileSchema),
|
||||
@@ -40,13 +37,10 @@ export function EditProfileForm({ currentUser }: EditProfileFormProps) {
|
||||
});
|
||||
|
||||
async function onSubmit(values: z.infer<typeof UpdateProfileSchema>) {
|
||||
if (!token) return;
|
||||
toast.info("Updating your profile...");
|
||||
try {
|
||||
await updateProfile(values, token);
|
||||
await updateProfile(currentUser.username, values);
|
||||
toast.success("Profile updated successfully!");
|
||||
router.push(`/users/${currentUser.username}`);
|
||||
router.refresh();
|
||||
} catch (err) {
|
||||
toast.error(`Failed to update profile. ${err}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user