feat: v2 rewrite — hexagonal arch, ActivityPub federation, NATS, deployment-ready (#1)
This commit was merged in pull request #1.
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";
|
||||
@@ -16,19 +15,15 @@ import {
|
||||
FormLabel,
|
||||
FormControl,
|
||||
FormMessage,
|
||||
FormDescription,
|
||||
} from "@/components/ui/form";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { TopFriendsCombobox } from "@/components/top-friends-combobox";
|
||||
|
||||
interface EditProfileFormProps {
|
||||
currentUser: Me;
|
||||
}
|
||||
|
||||
export function EditProfileForm({ currentUser }: EditProfileFormProps) {
|
||||
const router = useRouter();
|
||||
const { token } = useAuth();
|
||||
|
||||
const form = useForm<z.infer<typeof UpdateProfileSchema>>({
|
||||
resolver: zodResolver(UpdateProfileSchema),
|
||||
@@ -38,18 +33,14 @@ export function EditProfileForm({ currentUser }: EditProfileFormProps) {
|
||||
avatarUrl: currentUser.avatarUrl ?? undefined,
|
||||
headerUrl: currentUser.headerUrl ?? undefined,
|
||||
customCss: currentUser.customCss ?? undefined,
|
||||
topFriends: currentUser.topFriends ?? [],
|
||||
},
|
||||
});
|
||||
|
||||
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}`);
|
||||
}
|
||||
@@ -135,25 +126,6 @@ export function EditProfileForm({ currentUser }: EditProfileFormProps) {
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
name="topFriends"
|
||||
control={form.control}
|
||||
render={({ field }) => (
|
||||
<FormItem className="flex flex-col">
|
||||
<FormLabel>Top Friends</FormLabel>
|
||||
<FormControl>
|
||||
<TopFriendsCombobox
|
||||
value={field.value || []}
|
||||
onChange={field.onChange}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormDescription>
|
||||
Select up to 8 of your friends to display on your profile.
|
||||
</FormDescription>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</CardContent>
|
||||
<CardFooter className="border-t px-6 py-4">
|
||||
<Button type="submit" disabled={form.formState.isSubmitting}>
|
||||
|
||||
Reference in New Issue
Block a user