Skip to content

Commit

Permalink
feat(update-account): dynamic profile image action
Browse files Browse the repository at this point in the history
  • Loading branch information
crystalcheong committed Mar 22, 2023
1 parent 207cada commit 7a6302e
Showing 1 changed file with 33 additions and 13 deletions.
46 changes: 33 additions & 13 deletions src/pages/account/update.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
Text,
TextInput,
Title,
Transition,
useMantineTheme,
} from "@mantine/core";
import { FileWithPath } from "@mantine/dropzone";
Expand Down Expand Up @@ -383,6 +384,7 @@ const AccountUpdatePage = () => {
const handleRemoveProfileImage = async () => {
if (!isAuth || !currentUser) return;

setIsLoading(true);
await useAccountUpdateUser.mutateAsync(
{
id: currentUser.id,
Expand All @@ -403,6 +405,20 @@ const AccountUpdatePage = () => {
},
}
);
setIsLoading(false);
};

const handleProfileImageAction = async () => {
if (!isAuth || !currentUser) return;

const isDeletion = !profileImage.length;

if (isDeletion) {
await handleRemoveProfileImage();
} else {
setProfileImage([]);
updateFormState("image", "");
}
};

//#endregion //*======== Pre-Render Checks ===========
Expand Down Expand Up @@ -457,20 +473,24 @@ const AccountUpdatePage = () => {
files={profileImage}
onDrop={handleImageUpload}
/>
<Box
component="aside"
sx={{
display: "flex",
flexDirection: "column",
gap: theme.spacing.md,
placeContent: "center",
}}

<Transition
mounted={!!currentUser?.image?.length || !!profileImage.length}
transition="slide-right"
duration={400}
timingFunction="ease"
>
<Button onClick={handleRemoveProfileImage}>
Remove profile picture
</Button>
<Button onClick={() => setProfileImage([])}>Reset</Button>
</Box>
{(styles) => (
<Button
onClick={handleProfileImageAction}
disabled={!currentUser?.image?.length && !profileImage.length}
style={styles}
>
{profileImage.length ? "Revert" : "Delete"}
&nbsp;profile picture
</Button>
)}
</Transition>
</Group>

<TextInput
Expand Down

1 comment on commit 7a6302e

@vercel
Copy link

@vercel vercel bot commented on 7a6302e Mar 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

homey – ./

homey-crystalcheong.vercel.app
homey-git-main-crystalcheong.vercel.app
homey-sg.vercel.app

Please sign in to comment.