Skip to content

Commit 12a6e25

Browse files
authored
chore: handle res not ok (#953)
* Update Settings.tsx * Update Settings.tsx * Update Settings.tsx
1 parent 684c716 commit 12a6e25

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

apps/web/app/(org)/dashboard/settings/account/Settings.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@ export const Settings = ({
1818

1919
const { mutate: updateName, isPending: updateNamePending } = useMutation({
2020
mutationFn: async () => {
21-
await fetch("/api/settings/user/name", {
21+
const res = await fetch("/api/settings/user/name", {
2222
method: "POST",
23-
headers: {
24-
"Content-Type": "application/json",
25-
},
26-
body: JSON.stringify({ firstName, lastName }),
23+
headers: { "Content-Type": "application/json" },
24+
body: JSON.stringify({
25+
firstName: firstName.trim(),
26+
lastName: lastName.trim() ? lastName.trim() : null,
27+
}),
2728
});
29+
if (!res.ok) {
30+
throw new Error("Failed to update name");
31+
}
2832
},
2933
onSuccess: () => {
3034
toast.success("Name updated successfully");

0 commit comments

Comments
 (0)