mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-04-06 02:19:05 +00:00
update: implement account page reducer to manage account page state
This commit is contained in:
52
src/reducers/accountPageReducer.ts
Normal file
52
src/reducers/accountPageReducer.ts
Normal 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;
|
||||
Reference in New Issue
Block a user