Files
tehran_tala/apps/admin-panel/src/views/notify/create.vue
T

60 lines
2.2 KiB
Vue

<template>
<!-- Ported from legacy henza_admin/src/views/notify/create.vue. -->
<a-spin :spinning="loading">
<a-card title="ارسال نوتیفیکیشن" class="page-card">
<a-form layout="vertical" @submit.prevent="handleSubmit">
<div class="grid-2">
<a-form-item label="عنوان" :validate-status="err.title ? 'error' : ''" :help="err.title">
<a-input v-model:value="form.title" />
</a-form-item>
<a-form-item label="نوع کاربر">
<a-select v-model:value="form.type">
<a-select-option :value="0">همه مشتریان</a-select-option>
<a-select-option :value="2">مشتریان عمده</a-select-option>
<a-select-option :value="1">کارشناسان فروش</a-select-option>
</a-select>
</a-form-item>
</div>
<a-form-item label="متن پیام" :validate-status="err.text ? 'error' : ''" :help="err.text">
<a-textarea v-model:value="form.text" :auto-size="{ minRows: 4, maxRows: 8 }" />
</a-form-item>
<a-button type="primary" class="form-submit" @click="handleSubmit">ارسال</a-button>
</a-form>
</a-card>
</a-spin>
</template>
<script setup lang="ts">
import { reactive, ref } from 'vue';
import { message } from 'ant-design-vue';
import api from '../../api/client';
const loading = ref(false);
const form = reactive<Record<string, any>>({ title: '', text: '', type: 0 });
const err = reactive<Record<string, string>>({});
async function handleSubmit() {
Object.keys(err).forEach((k) => delete err[k]);
if (!form.title) err.title = 'عنوان الزامی است';
if (!form.text) err.text = 'متن پیام الزامی است';
if (Object.keys(err).length) return;
try {
loading.value = true;
const { data } = await api.post('notify', form);
message.success('نوتیفیکیشن ارسال شد');
form.title = '';
form.text = '';
} catch (e: any) {
message.error(e?.response?.data?.message ?? 'خطا در ارسال');
} finally {
loading.value = false;
}
}
</script>
<!-- .grid-2 now comes from the global utilities.less (dedup) -->