Skip to content

Commit cbcc197

Browse files
committed
Add sample profile
1 parent ee77736 commit cbcc197

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

frontend/src/api/user.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,11 @@ export const setGetProfile = async (access_token: string, user: User): Promise<U
2323
}),
2424
});
2525

26-
return response.json();
26+
// return response.json();
27+
return {
28+
username: "Hong Shan",
29+
bio: "I live in Redhill",
30+
linkedin: "www.linkedin.com/in/hongshan",
31+
github: "www.github.com/hongshan",
32+
}
2733
}

frontend/src/app/(auth)/profile/page.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { useEffect, useState } from "react";
1010
import { User } from "@/types/user";
1111
import { z } from "zod";
1212
import { zodResolver } from "@hookform/resolvers/zod";
13+
import Swal from "sweetalert2";
1314

1415
const formSchema = z.object({
1516
username: z.string()
@@ -43,23 +44,36 @@ const ProfilePage = () => {
4344
form.reset(data);
4445
}).catch((error) => {
4546
console.error("Profile Fetch Failed:", error);
46-
// or swal
47+
Swal.fire({
48+
icon: "error",
49+
title: "Profile Fetch Failed",
50+
text: "Please try again later",
51+
});
4752
});
4853
}, [token, form]);
4954

5055
const onSubmit = (data: z.infer<typeof formSchema>) => {
5156
setGetProfile(token, data).then((data) => {
5257
setUser(data);
5358
form.reset(data);
59+
Swal.fire({
60+
icon: "success",
61+
title: "Profile Updated",
62+
text: "Your profile has been updated successfully",
63+
});
5464
}).catch((error) => {
5565
console.error("Profile Update Failed:", error);
56-
// or swal
66+
Swal.fire({
67+
icon: "error",
68+
title: "Profile Update Failed",
69+
text: "Please try again later",
70+
})
5771
});
5872
};
5973

6074
return (
6175
<div className="mx-auto max-w-xl my-10 p-4">
62-
<h1 className="text-white font-extrabold text-h1">Welcome, {user?.username}</h1>
76+
<h1 className="text-white font-extrabold text-h1">Welcome, {user?.username}!</h1>
6377

6478
<Form {...form}>
6579
<form className="my-10 grid gap-4" onSubmit={form.handleSubmit(onSubmit)}>

0 commit comments

Comments
 (0)