From d45ed4737d37d1644dd44f54284750de6dc32603 Mon Sep 17 00:00:00 2001 From: Mohamed Muhsin Kamil Date: Sat, 16 Sep 2023 21:16:56 +0200 Subject: [PATCH] refactor: refactor type definition to data-hooks --- .../components/schedules/SchedulesTable.tsx | 71 +++++++++++-------- .../src/components/schedules/index.tsx | 12 ++-- .../src/client/data-hooks/accounts.tsx | 10 +-- .../src/client/data-hooks/payees.tsx | 10 +-- 4 files changed, 56 insertions(+), 47 deletions(-) diff --git a/packages/desktop-client/src/components/schedules/SchedulesTable.tsx b/packages/desktop-client/src/components/schedules/SchedulesTable.tsx index 8daa359ca89..8bfb8062e2f 100644 --- a/packages/desktop-client/src/components/schedules/SchedulesTable.tsx +++ b/packages/desktop-client/src/components/schedules/SchedulesTable.tsx @@ -41,13 +41,12 @@ type SchedulesTableProps = { type CompletedScheduleItem = { id: 'show-completed' }; type SchedulesTableItem = ScheduleEntity | CompletedScheduleItem; -export enum ScheduleItemAction { - PostTransaction = 'post-transaction', - SkipSchedule = 'skip', - CompleteSchedule = 'complete', - RestartSchedule = 'restart', - DeleteSchedule = 'delete', -} +export type ScheduleItemAction = + | 'post-transaction' + | 'skip' + | 'complete' + | 'restart' + | 'delete'; export const ROW_HEIGHT = 43; @@ -62,6 +61,39 @@ function OverflowMenu({ }) { const [open, setOpen] = useState(false); + const getMenuItems = () => { + const menuItems: { name: ScheduleItemAction; text: string }[] = []; + + if (status === 'due') { + menuItems.push({ + name: 'post-transaction', + text: 'Post transaction', + }); + } + + if (status === 'completed') { + menuItems.push({ + name: 'restart', + text: 'Restart', + }); + } else { + menuItems.push( + { + name: 'skip', + text: 'Skip next date', + }, + { + name: 'complete', + text: 'Complete', + }, + ); + } + + menuItems.push({ name: 'delete', text: 'Delete' }); + + return menuItems; + }; + return (