Skip to content

Commit

Permalink
handle profile edit errors
Browse files Browse the repository at this point in the history
  • Loading branch information
futurepaul authored and TonyGiorgio committed Mar 27, 2024
1 parent 787d89b commit 04400c0
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/components/EditProfileForm.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { createForm, email } from "@modular-forms/solid";
import { createFileUploader } from "@solid-primitives/upload";
import { Pencil } from "lucide-solid";
import { createSignal, Match, Switch } from "solid-js";
import { createSignal, Match, Show, Switch } from "solid-js";

import { Button, TextField, VStack } from "~/components";
import { Button, InfoBox, TextField, VStack } from "~/components";
import { useI18n } from "~/i18n/context";
import { useMegaStore } from "~/state/megaStore";
import { blobToBase64 } from "~/utils";
import { blobToBase64, eify } from "~/utils";

export type EditableProfile = {
nym?: string;
Expand All @@ -22,6 +22,7 @@ export function EditProfileForm(props: {
}) {
const [state] = useMegaStore();
const [uploading, setUploading] = createSignal(false);
const [uploadError, setUploadError] = createSignal<Error>();

const { files, selectFiles } = createFileUploader({
multiple: false,
Expand All @@ -43,25 +44,27 @@ export function EditProfileForm(props: {
});

async function handleSubmit(profile: EditableProfile) {
setUploading(true);
setUploadError(undefined);
try {
let imageUrl;
if (files() && files().length) {
setUploading(true);
const base64 = await blobToBase64(files()[0].file);
if (base64) {
imageUrl =
await state.mutiny_wallet?.upload_profile_pic(base64);
}
setUploading(false);
}
await props.onSave({
nym: profile.nym,
lightningAddress: profile.lightningAddress,
imageUrl: imageUrl ? imageUrl : props.initialProfile?.imageUrl
});
} catch (e) {
setUploadError(eify(e));
console.error(e);
}
setUploading(false);
}

return (
Expand Down Expand Up @@ -124,6 +127,9 @@ export function EditProfileForm(props: {
{props.cta}
</Button>
</Form>
<Show when={uploadError()}>
<InfoBox accent="red">{uploadError()?.message}</InfoBox>
</Show>
</VStack>
</VStack>
<div class="flex-1" />
Expand Down

0 comments on commit 04400c0

Please sign in to comment.