update: implement account page reducer to manage account page state

This commit is contained in:
Aaron William Po
2023-06-02 00:08:50 -04:00
parent 81cb95391a
commit 02d753fb41
5 changed files with 121 additions and 37 deletions

View File

@@ -1,10 +1,16 @@
import { AccountPageState, AccountPageAction } from '@/reducers/accountPageReducer';
import { Switch } from '@headlessui/react';
import { useRouter } from 'next/router';
import { FunctionComponent, useRef, useState } from 'react';
const DeleteAccount: FunctionComponent = () => {
const [deleteToggled, setDeleteToggled] = useState(false);
import { Dispatch, FunctionComponent, useRef } from 'react';
interface DeleteAccountProps {
pageState: AccountPageState;
dispatch: Dispatch<AccountPageAction>;
}
const DeleteAccount: FunctionComponent<DeleteAccountProps> = ({
dispatch,
pageState,
}) => {
const deleteRef = useRef<null | HTMLDialogElement>(null);
const router = useRouter();
@@ -20,14 +26,14 @@ const DeleteAccount: FunctionComponent = () => {
<Switch
className="toggle"
id="edit-toggle"
checked={deleteToggled}
checked={pageState.deleteAccountOpen}
onClick={() => {
setDeleteToggled((val) => !val);
dispatch({ type: 'TOGGLE_DELETE_ACCOUNT_VISIBILITY' });
}}
/>
</div>
</div>
{deleteToggled && (
{pageState.deleteAccountOpen && (
<>
<div className="mt-3">
<button