import { defineAsyncComponent, defineComponent, toRefs } from 'vue'; import { ref, reactive, computed } from 'vue'; import { ADD_STOCK_CATEGORY, EDIT_STOCK_CATEGORY } from '../../../graphql/operations/inventory.mutations'; import { useInventoryStore } from '../../../stores'; import { useApiUtil } from '../../../composables'; import { IStockCategory } from '../../../models/inventory'; const Modal = defineAsyncComponent( () => import('../../../components/SimpleModal.vue') ) const StockCategory = defineComponent({ name: 'stock-category', setup(props, ctx) { const inventoryStore = useInventoryStore(); const { withClientMutation } = useApiUtil(); let showModal = ref(false); let formTitle = ref(''); let form = reactive({} as IStockCategory); const formAction = ref(true); inventoryStore.fetchCategories(); const stockCategories = computed(() => inventoryStore.getCategories); function addStockCategory(): void { const payload = { ...form }; withClientMutation(ADD_STOCK_CATEGORY, { payload }, 'createStockCategory').then(result => inventoryStore.addCategory(result)); } function editStockCategory(): void { const payload = { name: form.name, description: form.description, }; withClientMutation(EDIT_STOCK_CATEGORY, { uid: form.uid, payload }, 'updateStockCategory').then(result => inventoryStore.updateCategory(result) ); } function FormManager(create: boolean, obj: IStockCategory | null): void { formAction.value = create; formTitle.value = (create ? 'CREATE' : 'EDIT') + ' ' + 'STOCK CATEGORY'; showModal.value = true; if (create) { Object.assign(form, {} as IStockCategory); } else { Object.assign(form, { ...obj }); } } function saveForm(): void { if (formAction.value === true) addStockCategory(); if (formAction.value === false) editStockCategory(); showModal.value = false; } return { form, FormManager, saveForm, stockCategories, showModal, formTitle, }; }, render() { return (


{this.stockCategories.map(category => { return ( ); })}
Category Name Description
{category?.name}
{category?.description}
{/* StockCategory Form Modal */} {this.showModal ? ( (this.showModal = false)} contentWidth="w-1/4"> {{ header: () =>

{this.formTitle}

, body: () => { return (