admin-panel: convert user and category add/edit forms into modals

Same pattern as branch/workshop/city: open/id props switch UserCreate.vue and
apps/category/Add.vue into BaseFormModal mode; the /user/create,
/user/edit/:id and /category/add/:id? routes are unchanged as a fallback.
ListUser.vue's pre-existing add button (previously a router.push, added
outside the original port and left there per its own comment) now opens the
modal via ListPageHeader instead.

Verified: pnpm build passes.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
s.esmaeili
2026-09-14 16:49:24 +03:30
co-authored by Claude Sonnet 5
parent 1ac3b03ad5
commit a8988c18a2
4 changed files with 205 additions and 29 deletions
+85 -3
View File
@@ -2,12 +2,77 @@
<!--
Ported from legacy henza_admin/src/views/user/UserCreate.vue.
Serves BOTH create and edit — UserEdit.vue is only a wrapper around it.
Converted to a modal (BaseFormModal): the /user/create and /user/edit/:id
routes still exist and still render this component directly as a
route-based fallback, but ListUser.vue now opens it as a modal via
open/id props.
Legacy fields: fname, lname, mobile, ut, password, password_confirmation.
The schema stores one `fullName`, so the two name inputs are joined on submit
and split back on load.
-->
<a-spin :spinning="loading">
<BaseFormModal
v-if="asModal"
:open="Boolean(open)"
:id="id"
add-title="افزودن مدیر"
edit-title="ویرایش مدیر"
:loading="loading"
:submitting="loading"
@update:open="$emit('update:open', $event)"
@submit="handleSubmit"
>
<div class="grid-3">
<a-form-item label="نام" :validate-status="err.fname ? 'error' : ''" :help="err.fname">
<a-input v-model:value="form.fname" />
</a-form-item>
<a-form-item
label="نام خانوادگی"
:validate-status="err.lname ? 'error' : ''"
:help="err.lname"
>
<a-input v-model:value="form.lname" />
</a-form-item>
<a-form-item
label="شماره موبایل"
:validate-status="err.mobile ? 'error' : ''"
:help="err.mobile"
>
<a-input v-model:value="form.mobile" />
</a-form-item>
<a-form-item label="نوع کاربری" :validate-status="err.ut ? 'error' : ''" :help="err.ut">
<a-select v-model:value="form.ut" allow-clear placeholder="انتخاب کنید">
<a-select-option v-for="t in userTypes" :key="t.id" :value="t.id">
{{ t.title }}
</a-select-option>
</a-select>
</a-form-item>
<a-form-item
label="رمز عبور"
:validate-status="err.password ? 'error' : ''"
:help="err.password"
>
<a-input-password v-model:value="form.password" />
</a-form-item>
<a-form-item
label="تأیید رمز عبور"
:validate-status="err.password_confirmation ? 'error' : ''"
:help="err.password_confirmation"
>
<a-input-password v-model:value="form.password_confirmation" />
</a-form-item>
</div>
<p v-if="id" class="hint">برای تغییر ندادن رمز عبور، هر دو فیلد رمز را خالی بگذارید.</p>
</BaseFormModal>
<!-- route-based fallback for direct links to /user/create and /user/edit/:id -->
<a-spin v-else :spinning="loading">
<a-form layout="vertical" @submit.prevent="handleSubmit">
<a-card :title="id ? 'ویرایش مدیر' : 'افزودن مدیر'" class="mb-base">
<div class="grid-3">
@@ -68,12 +133,24 @@
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<{
open?: boolean;
id?: string;
}>();
const emit = defineEmits<{
(e: 'update:open', value: boolean): void;
(e: 'success'): void;
}>();
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 userTypes = ref<{ id: number; title: string }[]>([]);
@@ -121,7 +198,12 @@ async function handleSubmit() {
await api.post('users', payload);
}
message.info('اطلاعات با موفقیت به ثبت رسید.');
router.push('/user/list');
if (asModal) {
emit('success');
emit('update:open', false);
} else {
router.push('/user/list');
}
} catch (e: any) {
message.error(e?.response?.data?.message ?? 'خطا در ثبت اطلاعات.');
} finally {