Skip to content

Commit 4eecd1d

Browse files
committed
fix: improve avatar upload validation in settings form
skip if data.avatar is not an url. this was causing error when user just wanted to change display name
1 parent 27aef52 commit 4eecd1d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

components/settings/settings-form.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import {
3737
readAsBase64,
3838
} from "../image-uploader";
3939
import { HYPERCERTS_API_URL_REST } from "@/configs/hypercerts";
40+
import isURL from "validator/lib/isURL";
4041

4142
const formSchema = z.object({
4243
displayName: z.string().max(30, "Max. 30 characters").optional(),
@@ -88,8 +89,10 @@ export const SettingsForm = () => {
8889

8990
const onSubmit = async (data: SettingsFormValues) => {
9091
try {
91-
if (data.avatar) {
92+
// if data.avatar is not an url, that means the user has uploaded a new image
93+
if (data.avatar && !isURL(data.avatar)) {
9294
const formData = new FormData();
95+
9396
const blob = base64ToBlob(data.avatar);
9497
const file = new File([blob], "avatar.jpg", {
9598
type: "image/jpeg",
@@ -193,8 +196,8 @@ export const SettingsForm = () => {
193196

194197
const isSubmitDisabled =
195198
form.formState.isSubmitting ||
196-
isFormDisabled ||
197199
!form.formState.isValid ||
200+
isFormDisabled ||
198201
!form.formState.isDirty;
199202

200203
const shouldShowAvatar =

0 commit comments

Comments
 (0)