From b54fd09a92833ed68464a5dff7b3e8b90114ed0f Mon Sep 17 00:00:00 2001 From: Tobi Abiodun Date: Sun, 28 Jan 2024 19:18:29 -0500 Subject: [PATCH] feat(lists): Add lists functionality to work page --- src/components/BaseButton.vue | 5 + src/hooks/lists/useCreateList.ts | 44 +++++ src/pages/Work.vue | 7 + src/pages/lists/ListDropdown.vue | 282 ++++++++++++++++++++++++++++++ src/pages/lists/Lists.vue | 286 ++++++++++++++++++------------- src/pages/lists/NewListForm.vue | 114 ++++++++++++ 6 files changed, 615 insertions(+), 123 deletions(-) create mode 100644 src/hooks/lists/useCreateList.ts create mode 100644 src/pages/lists/ListDropdown.vue create mode 100644 src/pages/lists/NewListForm.vue diff --git a/src/components/BaseButton.vue b/src/components/BaseButton.vue index d86f6736a..f6addc23c 100644 --- a/src/components/BaseButton.vue +++ b/src/components/BaseButton.vue @@ -99,6 +99,10 @@ export default defineComponent({ type: Number, default: 5000, }, + buttonClasses: { + type: Object, + default: () => ({}), + }, }, setup(props) { @@ -131,6 +135,7 @@ export default defineComponent({ 'items-center': true, 'justify-center': true, 'base-button': true, + ...props.buttonClasses, } as Record; if (props.variant) { styleObject[props.variant] = true; diff --git a/src/hooks/lists/useCreateList.ts b/src/hooks/lists/useCreateList.ts new file mode 100644 index 000000000..b20c7d3fb --- /dev/null +++ b/src/hooks/lists/useCreateList.ts @@ -0,0 +1,44 @@ +import useDialogs from '@/hooks/useDialogs'; +import axios from 'axios'; +import { i18n } from '@/modules/i18n'; +import NewListForm from '@/pages/lists/NewListForm.vue'; + +export default function useCreateList(onComplete: () => void, model: string) { + const { component } = useDialogs(); + + const createList = async () => { + let newList = {}; + const response = await component({ + title: i18n.global.t('lists.create_new_list'), + component: NewListForm, // This should be your New List Form component + classes: 'w-full overflow-auto p-3', + modalClasses: 'bg-white max-w-3xl shadow', + props: { + model, + }, + listeners: { + onNewList(payload: Record) { + newList = payload; + }, + }, + }); + + if (response === 'ok' && newList) { + try { + await axios.post( + `${import.meta.env.VITE_APP_API_BASE_URL}/lists`, + newList, + ); + i18n.global.t('lists.list_created_successfully'); + } catch (error) { + console.error('Error creating list:', error); + } + } + + onComplete(); + }; + + return { + createList, + }; +} diff --git a/src/pages/Work.vue b/src/pages/Work.vue index e5b9aefbb..663c035e4 100644 --- a/src/pages/Work.vue +++ b/src/pages/Work.vue @@ -663,6 +663,11 @@