Skip to content

Commit 07ccba6

Browse files
committed
feat: enhance user profile handling by generating unique avatar filenames and improving form input validation
1 parent 5db7eaf commit 07ccba6

File tree

5 files changed

+18
-12
lines changed

5 files changed

+18
-12
lines changed

src/app/api/auth/github/callback/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export async function GET(request: Request) {
2727

2828
const uploadedFileResponse = await storageActions.uploadByUrl({
2929
url: githubUser?.data?.avatar_url,
30-
key: `${DIRECTORY_NAME.USER_AVATARS}/${githubUser?.data?.login}.jpeg`,
30+
key: `${DIRECTORY_NAME.USER_AVATARS}/${crypto.randomUUID()}.jpeg`,
3131
});
3232

3333
const bootedSocialUser = await userActions.bootSocialUser({

src/app/dashboard/settings/_components/GeneralForm.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import z from "zod";
2424
import { Loader2, User2 } from "lucide-react";
2525
import { toast } from "sonner";
2626
import ImageDropzoneWithCropper from "@/components/ImageDropzoneWithCropper";
27+
import { filterUndefined } from "@/lib/utils";
2728

2829
// fields
2930
// name -> ✅
@@ -54,7 +55,7 @@ const GeneralForm: React.FC<Props> = ({ user }) => {
5455
},
5556
});
5657
const form = useForm({
57-
defaultValues: {
58+
defaultValues: filterUndefined({
5859
name: user?.name,
5960
username: user?.username,
6061
bio: user?.bio,
@@ -64,7 +65,7 @@ const GeneralForm: React.FC<Props> = ({ user }) => {
6465
education: user.education,
6566
designation: user.designation,
6667
location: user.location,
67-
},
68+
}),
6869
resolver: zodResolver(UserActionInput.updateMyProfileInput),
6970
});
7071

@@ -162,7 +163,11 @@ const GeneralForm: React.FC<Props> = ({ user }) => {
162163
<FormItem>
163164
<FormLabel>{_t("Website url")}</FormLabel>
164165
<FormControl>
165-
<Input className="py-6" {...field} />
166+
<Input
167+
className="py-6"
168+
onChange={field.onChange}
169+
value={field.value ?? undefined}
170+
/>
166171
</FormControl>
167172
<FormDescription />
168173
<FormMessage />

src/backend/services/inputs/user.input.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ export const UserActionInput = {
2727
})
2828
.optional()
2929
.nullable(),
30-
education: z.string().optional(),
31-
designation: z.string().optional(),
32-
bio: z.string().optional(),
33-
websiteUrl: z.string().url().optional(),
34-
location: z.string().optional(),
30+
education: z.string().optional().nullable(),
31+
designation: z.string().optional().nullable(),
32+
bio: z.string().optional().nullable(),
33+
websiteUrl: z.string().url().optional().nullable(),
34+
location: z.string().optional().nullable(),
3535
social_links: z
3636
.object({
3737
github: z
@@ -84,7 +84,7 @@ export const UserActionInput = {
8484
.optional(),
8585
})
8686
.optional(),
87-
profile_readme: z.string().optional(),
88-
skills: z.string().optional(),
87+
profile_readme: z.string().optional().nullable(),
88+
skills: z.string().optional().nullable(),
8989
}),
9090
};

src/components/ImageDropzoneWithCropper.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ const ImageDropzoneWithCropper: React.FC<DropzoneWithCropperProps> = ({
8989
useDropzone({
9090
maxFiles: 1,
9191
disabled,
92+
accept: { "image/*": [".*"] },
9293
async onDrop(acceptedFiles) {
9394
if (acceptedFiles.length > 0) {
9495
const base64 = (await getImageBase64(acceptedFiles[0])) as string;

src/lib/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export const removeNullOrUndefinedFromObject = (obj: any) => {
105105
return newObj;
106106
};
107107

108-
export function filterUndefined<T>(
108+
export function filterUndefined<T = unknown>(
109109
mapping: Partial<Record<keyof T, any>>
110110
): Partial<Record<string, any>> {
111111
return Object.fromEntries(

0 commit comments

Comments
 (0)