diff --git a/apps/admin-panel/src/views/branch/AddBranches.vue b/apps/admin-panel/src/views/branch/AddBranches.vue index 21c51a4..c5acff5 100644 --- a/apps/admin-panel/src/views/branch/AddBranches.vue +++ b/apps/admin-panel/src/views/branch/AddBranches.vue @@ -2,11 +2,55 @@ - + +
+ + + + + + + + + + + + {{ u.name }} + + + +
+ + + + +
+ + +
@@ -47,12 +91,27 @@ import { onMounted, reactive, ref } from 'vue'; import { useRoute, useRouter } from 'vue-router'; import { message } from 'ant-design-vue'; +import BaseFormModal from '../../components/common/BaseFormModal.vue'; import api from '../../api/client'; +const props = defineProps<{ + /** Present -> rendered as a modal by the parent list page. */ + open?: boolean; + id?: string; +}>(); +const emit = defineEmits<{ + (e: 'update:open', value: boolean): void; + (e: 'success'): void; +}>(); + +// Fixed at mount: the parent decides once whether this instance is a modal +// or the plain /branch/add or /branch/edit/:id route. +const asModal = props.open !== undefined; + const route = useRoute(); const router = useRouter(); -const id = route.params.id as string | undefined; +const id = asModal ? props.id : (route.params.id as string | undefined); const loading = ref(false); const adminUsers = ref<{ id: string; name: string }[]>([]); @@ -82,7 +141,12 @@ async function handleSubmit() { await api.post('branch', form); } message.info('اطلاعات با موفقیت به ثبت رسید.'); - router.push('/branch/list'); + if (asModal) { + emit('success'); + emit('update:open', false); + } else { + router.push('/branch/list'); + } } catch (e: any) { message.error(e?.response?.data?.message ?? 'خطا در ثبت اطلاعات.'); } finally { diff --git a/apps/admin-panel/src/views/branch/FacilityList.vue b/apps/admin-panel/src/views/branch/FacilityList.vue index 32ac31e..9bca71e 100644 --- a/apps/admin-panel/src/views/branch/FacilityList.vue +++ b/apps/admin-panel/src/views/branch/FacilityList.vue @@ -10,12 +10,21 @@ - legacy binds `slot-scope="text,record"` then reads `text.record.id`, i.e. the row arrives as the FIRST argument; the Vue 3 slot gives us `record` directly, which is the same row. + + The add/edit modal itself is passed in via the default slot (branch and + workshop use different forms), so this component stays generic instead of + growing a v-if per caller. --> + + + + @@ -39,21 +50,48 @@ import { useRouter } from 'vue-router'; import { message } from 'ant-design-vue'; import { CheckOutlined, CloseOutlined, EditOutlined } from '@ant-design/icons-vue'; import XTable from '../../components/x-table/XTable.vue'; +import ListPageHeader from '../../components/common/ListPageHeader.vue'; import api from '../../api/client'; import type { XTbl } from '../../components/x-table/model'; const props = defineProps<{ title: string; model: XTbl; - /** Where the edit pencil navigates, e.g. '/branch/edit' or '/workshop/edit'. */ + /** Where the edit pencil navigates when no modal form is supplied, e.g. + * '/branch/edit' or '/workshop/edit'. */ editPath: string; /** The toggle endpoint, e.g. 'branch/active' or 'workshop/active'. */ activePath: string; + /** When set, edit/add open the #form slot's modal instead of navigating, + * gated on this rid (the same one the /add route used). */ + addRid?: string; + addLabel?: string; }>(); const router = useRouter(); const tbl = ref<{ fetch: () => Promise } | null>(null); +const modalOpen = ref(false); +const editingId = ref(undefined); + +function openAdd() { + editingId.value = undefined; + modalOpen.value = true; +} + +function openEdit(id: string) { + editingId.value = id; + modalOpen.value = true; +} + +function onUpdateOpen(value: boolean) { + modalOpen.value = value; +} + +function onSuccess() { + tbl.value?.fetch(); +} + function toEdit(id: string) { router.push(`${props.editPath}/${id}`); } @@ -69,4 +107,3 @@ async function setOffer(id: string) { } } - diff --git a/apps/admin-panel/src/views/branch/ListBranches.vue b/apps/admin-panel/src/views/branch/ListBranches.vue index 1398718..10082d7 100644 --- a/apps/admin-panel/src/views/branch/ListBranches.vue +++ b/apps/admin-panel/src/views/branch/ListBranches.vue @@ -6,11 +6,18 @@ :model="model" edit-path="/branch/edit" active-path="branch/active" - /> + add-rid="branch.create" + add-label="افزودن شعبه" + > + +