Skip to content

Commit db75ece

Browse files
aaryan610sriramveeraghanta
authored andcommitted
chore: deactivate user option added (#2841)
* dev: deactivate user option added * chore: new layout for profile settings * fix: build errors * fix: user profile activity
1 parent 3c89ef8 commit db75ece

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+796
-622
lines changed

web/components/account/delete-account-modal.tsx renamed to web/components/account/deactivate-account-modal.tsx

+50-43
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,90 @@
1-
// react
21
import React, { useState } from "react";
3-
// next
42
import { useRouter } from "next/router";
3+
import { mutate } from "swr";
4+
import { useTheme } from "next-themes";
5+
import { Dialog, Transition } from "@headlessui/react";
6+
import { AlertTriangle } from "lucide-react";
7+
// mobx store
8+
import { useMobxStore } from "lib/mobx/store-provider";
9+
// ui
10+
import { Button } from "@plane/ui";
511
// hooks
612
import useToast from "hooks/use-toast";
713
// services
814
import { AuthService } from "services/auth.service";
9-
// headless ui
10-
import { Dialog, Transition } from "@headlessui/react";
11-
// icons
12-
import { Trash2 } from "lucide-react";
13-
import { UserService } from "services/user.service";
14-
import { useTheme } from "next-themes";
15-
import { mutate } from "swr";
1615

1716
type Props = {
1817
isOpen: boolean;
1918
onClose: () => void;
2019
};
2120

2221
const authService = new AuthService();
23-
const userService = new UserService();
2422

25-
const DeleteAccountModal: React.FC<Props> = (props) => {
23+
export const DeactivateAccountModal: React.FC<Props> = (props) => {
2624
const { isOpen, onClose } = props;
27-
const [isDeleteLoading, setIsDeleteLoading] = useState(false);
25+
26+
// states
27+
const [switchingAccount, setSwitchingAccount] = useState(false);
28+
const [isDeactivating, setIsDeactivating] = useState(false);
29+
30+
const {
31+
user: { deactivateAccount },
32+
} = useMobxStore();
2833

2934
const router = useRouter();
35+
3036
const { setTheme } = useTheme();
37+
3138
const { setToastAlert } = useToast();
3239

33-
const handleSignOut = async () => {
40+
const handleClose = () => {
41+
setSwitchingAccount(false);
42+
setIsDeactivating(false);
43+
onClose();
44+
};
45+
46+
const handleSwitchAccount = async () => {
47+
setSwitchingAccount(true);
48+
3449
await authService
3550
.signOut()
3651
.then(() => {
3752
mutate("CURRENT_USER_DETAILS", null);
3853
setTheme("system");
3954
router.push("/");
55+
handleClose();
4056
})
4157
.catch(() =>
4258
setToastAlert({
4359
type: "error",
4460
title: "Error!",
4561
message: "Failed to sign out. Please try again.",
4662
})
47-
);
63+
)
64+
.finally(() => setSwitchingAccount(false));
4865
};
4966

5067
const handleDeleteAccount = async () => {
51-
setIsDeleteLoading(true);
52-
await userService
53-
.deleteAccount()
68+
setIsDeactivating(true);
69+
70+
await deactivateAccount()
5471
.then(() => {
5572
setToastAlert({
5673
type: "success",
5774
title: "Success!",
5875
message: "Account deleted successfully.",
5976
});
60-
mutate("CURRENT_USER_DETAILS", null);
61-
setTheme("system");
77+
handleClose();
6278
router.push("/");
6379
})
6480
.catch((err) =>
6581
setToastAlert({
6682
type: "error",
6783
title: "Error!",
68-
message: err?.data?.error,
84+
message: err?.error,
6985
})
70-
);
71-
setIsDeleteLoading(false);
72-
};
73-
74-
const handleClose = () => {
75-
onClose();
86+
)
87+
.finally(() => setIsDeactivating(false));
7688
};
7789

7890
return (
@@ -105,32 +117,29 @@ const DeleteAccountModal: React.FC<Props> = (props) => {
105117
<div className="px-4 pt-5 pb-4 sm:p-6 sm:pb-4">
106118
<div className="">
107119
<div className="flex items-center gap-x-4">
108-
<div className="mx-auto flex h-12 w-12 flex-shrink-0 items-center justify-center rounded-full bg-red-100 sm:mx-0 sm:h-10 sm:w-10">
109-
<Trash2 className="h-5 w-5 text-red-600" aria-hidden="true" />
120+
<div className="grid place-items-center rounded-full bg-red-500/20 p-4">
121+
<AlertTriangle className="h-6 w-6 text-red-600" aria-hidden="true" />
110122
</div>
111123
<Dialog.Title as="h3" className="text-2xl font-medium leading-6 text-onboarding-text-100">
112-
Not the right workspace?
124+
Deactivate account?
113125
</Dialog.Title>
114126
</div>
115127

116128
<div className="mt-6 px-4">
117129
<ul className="text-onboarding-text-300 list-disc font-normal text-base">
118-
<li>Delete this account if you have another and wont use this account.</li>
119-
<li>Switch to another account if youd like to come back to this account another time.</li>
130+
<li>Deactivate this account if you have another and won{"'"}t use this account.</li>
131+
<li>Switch to another account if you{"'"}d like to come back to this account another time.</li>
120132
</ul>
121133
</div>
122134
</div>
123135
</div>
124-
<div className="flex items-center justify-end gap-4 p-4 mb-2 sm:px-6">
125-
<span className="text-sm font-medium hover:cursor-pointer" onClick={handleSignOut}>
126-
Switch account
127-
</span>
128-
<button
129-
className="py-1.5 px-3 font-medium rounded-sm text-red-500 border border-red-500 text-sm "
130-
onClick={handleDeleteAccount}
131-
>
132-
{isDeleteLoading ? "Deleting..." : "Delete account"}
133-
</button>
136+
<div className="flex items-center justify-end gap-2 p-4 mb-2 sm:px-6">
137+
<Button variant="link-primary" onClick={handleSwitchAccount} loading={switchingAccount}>
138+
{switchingAccount ? "Switching..." : "Switch account"}
139+
</Button>
140+
<Button variant="outline-danger" onClick={handleDeleteAccount}>
141+
{isDeactivating ? "Deactivating..." : "Deactivate account"}
142+
</Button>
134143
</div>
135144
</Dialog.Panel>
136145
</Transition.Child>
@@ -140,5 +149,3 @@ const DeleteAccountModal: React.FC<Props> = (props) => {
140149
</Transition.Root>
141150
);
142151
};
143-
144-
export default DeleteAccountModal;

web/components/account/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export * from "./deactivate-account-modal";
12
export * from "./email-code-form";
23
export * from "./email-password-form";
34
export * from "./email-forgot-password-form";

web/components/auth-screens/project/join-project.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ import JoinProjectImg from "public/auth/project-not-authorized.svg";
1313
export const JoinProject: React.FC = () => {
1414
const [isJoiningProject, setIsJoiningProject] = useState(false);
1515

16-
const { project: projectStore } = useMobxStore();
16+
const {
17+
user: { joinProject },
18+
} = useMobxStore();
1719

1820
const router = useRouter();
1921
const { workspaceSlug, projectId } = router.query;
@@ -23,7 +25,7 @@ export const JoinProject: React.FC = () => {
2325

2426
setIsJoiningProject(true);
2527

26-
projectStore.joinProject(workspaceSlug.toString(), [projectId.toString()]).finally(() => {
28+
joinProject(workspaceSlug.toString(), [projectId.toString()]).finally(() => {
2729
setIsJoiningProject(false);
2830
});
2931
};

web/components/command-palette/command-pallette.tsx

+7-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import useSWR from "swr";
44
import { observer } from "mobx-react-lite";
55
// hooks
66
import useToast from "hooks/use-toast";
7-
import useUser from "hooks/use-user";
87
// components
98
import { CommandModal, ShortcutsModal } from "components/command-palette";
109
import { BulkDeleteIssuesModal } from "components/core";
@@ -30,7 +29,11 @@ export const CommandPalette: FC = observer(() => {
3029
const router = useRouter();
3130
const { workspaceSlug, projectId, issueId, cycleId, moduleId } = router.query;
3231
// store
33-
const { commandPalette, theme: themeStore } = useMobxStore();
32+
const {
33+
commandPalette,
34+
theme: { toggleSidebar },
35+
user: { currentUser },
36+
} = useMobxStore();
3437
const {
3538
toggleCommandPaletteModal,
3639
isCreateIssueModalOpen,
@@ -52,9 +55,6 @@ export const CommandPalette: FC = observer(() => {
5255
isDeleteIssueModalOpen,
5356
toggleDeleteIssueModal,
5457
} = commandPalette;
55-
const { toggleSidebar } = themeStore;
56-
57-
const { user } = useUser();
5858

5959
const { setToastAlert } = useToast();
6060

@@ -153,7 +153,7 @@ export const CommandPalette: FC = observer(() => {
153153
return () => document.removeEventListener("keydown", handleKeyDown);
154154
}, [handleKeyDown]);
155155

156-
if (!user) return null;
156+
if (!currentUser) return null;
157157

158158
return (
159159
<>
@@ -223,7 +223,7 @@ export const CommandPalette: FC = observer(() => {
223223
onClose={() => {
224224
toggleBulkDeleteIssueModal(false);
225225
}}
226-
user={user}
226+
user={currentUser}
227227
/>
228228
<CommandModal />
229229
</>

0 commit comments

Comments
 (0)