Update: Implement delete account feature + package updates

This commit is contained in:
Aaron William Po
2023-06-01 19:56:14 -04:00
parent 6fcd7b53d0
commit b644e7eeee
9 changed files with 518 additions and 492 deletions

View File

@@ -0,0 +1,70 @@
import { Switch } from '@headlessui/react';
import { useRouter } from 'next/router';
import { FunctionComponent, useRef, useState } from 'react';
const DeleteAccount: FunctionComponent = () => {
const [deleteToggled, setDeleteToggled] = useState(false);
const deleteRef = useRef<null | HTMLDialogElement>(null);
const router = useRouter();
return (
<div className="card w-full space-y-4">
<div className="card-body">
<div className="flex w-full items-center justify-between space-x-5">
<div className="">
<h1 className="text-lg font-bold">Delete Your Account</h1>
<p>Want to leave? Delete your account here.</p>
</div>
<div>
<Switch
className="toggle"
id="edit-toggle"
checked={deleteToggled}
onClick={() => {
setDeleteToggled((val) => !val);
}}
/>
</div>
</div>
{deleteToggled && (
<>
<div className="mt-3">
<button
className="btn-primary btn w-full"
onClick={() => deleteRef.current!.showModal()}
>
Delete my account
</button>
<dialog id="delete-modal" className="modal" ref={deleteRef}>
<div className="modal-box text-center">
<h3 className="text-lg font-bold">{`You're about to delete your account.`}</h3>
<p className="">This action is permanent and cannot be reversed.</p>
<div className="modal-action flex-col space-x-0 space-y-3">
<button
className="btn-error btn-sm btn w-full"
onClick={async () => {
deleteRef.current!.close();
await router.replace('/api/users/logout');
}}
>
Okay, delete my account
</button>
<button
className="btn-success btn-sm btn w-full"
onClick={() => deleteRef.current!.close()}
>
Go back
</button>
</div>
</div>
</dialog>
</div>
</>
)}
</div>
</div>
);
};
export default DeleteAccount;

View File

@@ -20,7 +20,7 @@ const Security: FunctionComponent = () => {
const onSubmit: SubmitHandler<z.infer<typeof UpdatePasswordSchema>> = async (data) => {
await sendUpdatePasswordRequest(data);
setEditToggled(value => !value)
setEditToggled((value) => !value);
reset();
};

View File

@@ -27,9 +27,9 @@ const CustomToast: FC<{ children: ReactNode }> = ({ children }) => {
const alertType = toastToClassName(t.type);
return (
<div
className={`alert ${alertType} w-11/12 flex-row items-center shadow-lg animate-in fade-in duration-200 lg:w-2/12`}
className={`alert ${alertType} w-11/12 flex-row items-center shadow-lg animate-in fade-in duration-200 lg:w-4/12`}
>
<p className='text-sm'>{resolveValue(t.message, t)}</p>
<p>{resolveValue(t.message, t)}</p>
{t.type !== 'loading' && (
<div>
<button

View File

@@ -12,7 +12,7 @@ const DesktopLinks: FC = () => {
return (
<div className="block flex-none">
<ul className="menu menu-horizontal p-0">
<ul className="menu menu-horizontal menu-sm px-1">
{pages.map((page) => {
return (
<li key={page.slug}>
@@ -43,7 +43,7 @@ const MobileLinks: FC = () => {
</label>
<ul
tabIndex={0}
className="dropdown-content menu rounded-box menu-compact mt-3 w-48 bg-base-100 p-2 shadow"
className="menu-compact dropdown-content menu rounded-box mt-3 w-48 bg-base-100 p-2 shadow"
>
{pages.map((page) => (
<li key={page.slug}>

View File

@@ -14,7 +14,8 @@ const Button: FunctionComponent<FormButtonProps> = ({
// eslint-disable-next-line react/button-has-type
<button
type={type}
className={`btn-primary btn w-full rounded-xl ${isSubmitting ? 'loading' : ''}`}
className={`btn-primary btn w-full rounded-xl`}
disabled={isSubmitting}
>
{children}
</button>