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

@@ -0,0 +1,52 @@
export interface AccountPageState {
accountInfoOpen: boolean;
securityOpen: boolean;
deleteAccountOpen: boolean;
}
export type AccountPageAction =
| { type: 'TOGGLE_ACCOUNT_INFO_VISIBILITY' }
| { type: 'TOGGLE_SECURITY_VISIBILITY' }
| { type: 'TOGGLE_DELETE_ACCOUNT_VISIBILITY' }
| { type: 'CLOSE_ALL' };
const accountPageReducer = (
state: AccountPageState,
action: AccountPageAction,
): AccountPageState => {
switch (action.type) {
case 'TOGGLE_ACCOUNT_INFO_VISIBILITY': {
return {
accountInfoOpen: !state.accountInfoOpen,
securityOpen: false,
deleteAccountOpen: false,
};
}
case 'TOGGLE_DELETE_ACCOUNT_VISIBILITY': {
return {
accountInfoOpen: false,
securityOpen: false,
deleteAccountOpen: !state.deleteAccountOpen,
};
}
case 'TOGGLE_SECURITY_VISIBILITY': {
return {
accountInfoOpen: false,
securityOpen: !state.securityOpen,
deleteAccountOpen: false,
};
}
case 'CLOSE_ALL': {
return {
accountInfoOpen: false,
securityOpen: false,
deleteAccountOpen: false,
};
}
default: {
throw new Error('Invalid action type.');
}
}
};
export default accountPageReducer;