Initial Mento CRM: portal OTP, reports, SMS, and deploy for crm.montzar.ir.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,266 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue';
|
||||
import axios from 'axios';
|
||||
import { api } from '@/lib/api';
|
||||
import { formatMoney } from '@/lib/money';
|
||||
import type {
|
||||
CreateProductRequest,
|
||||
OrganizationDto,
|
||||
ProductDto,
|
||||
} from '@mento/shared';
|
||||
|
||||
const loading = ref(false);
|
||||
const saving = ref(false);
|
||||
const error = ref('');
|
||||
const products = ref<ProductDto[]>([]);
|
||||
const enabledCurrencies = ref<string[]>(['IRR']);
|
||||
|
||||
const name = ref('');
|
||||
const sku = ref('');
|
||||
const unitPrice = ref('');
|
||||
const currency = ref('IRR');
|
||||
const description = ref('');
|
||||
|
||||
async function load() {
|
||||
loading.value = true;
|
||||
error.value = '';
|
||||
try {
|
||||
const [productsRes, orgRes] = await Promise.all([
|
||||
api.get<ProductDto[]>('/products'),
|
||||
api.get<OrganizationDto>('/organizations/current'),
|
||||
]);
|
||||
products.value = productsRes.data;
|
||||
enabledCurrencies.value = orgRes.data.enabledCurrencies?.length
|
||||
? orgRes.data.enabledCurrencies
|
||||
: [orgRes.data.baseCurrency || 'IRR'];
|
||||
currency.value = orgRes.data.baseCurrency || 'IRR';
|
||||
} catch (e) {
|
||||
if (axios.isAxiosError(e) && !e.response) {
|
||||
error.value = 'اتصال به API برقرار نشد.';
|
||||
} else {
|
||||
error.value = 'بارگذاری محصولات ناموفق بود.';
|
||||
}
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function createProduct() {
|
||||
if (!name.value.trim()) {
|
||||
error.value = 'نام محصول را وارد کنید.';
|
||||
return;
|
||||
}
|
||||
saving.value = true;
|
||||
error.value = '';
|
||||
try {
|
||||
const payload: CreateProductRequest = {
|
||||
name: name.value.trim(),
|
||||
sku: sku.value || undefined,
|
||||
description: description.value || undefined,
|
||||
unitPrice: unitPrice.value === '' ? null : Number(unitPrice.value),
|
||||
currency: currency.value || 'IRR',
|
||||
};
|
||||
await api.post('/products', payload);
|
||||
name.value = '';
|
||||
sku.value = '';
|
||||
unitPrice.value = '';
|
||||
description.value = '';
|
||||
await load();
|
||||
} catch (e) {
|
||||
if (axios.isAxiosError(e)) {
|
||||
const msg = (e.response?.data as { message?: string | string[] })?.message;
|
||||
error.value = Array.isArray(msg)
|
||||
? msg.join('، ')
|
||||
: (msg ?? 'ثبت محصول ناموفق بود');
|
||||
} else {
|
||||
error.value = 'ثبت محصول ناموفق بود';
|
||||
}
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function toggleActive(product: ProductDto) {
|
||||
await api.patch(`/products/${product.id}`, { isActive: !product.isActive });
|
||||
await load();
|
||||
}
|
||||
|
||||
async function removeProduct(product: ProductDto) {
|
||||
if (!confirm(`محصول «${product.name}» حذف شود؟`)) return;
|
||||
await api.delete(`/products/${product.id}`);
|
||||
await load();
|
||||
}
|
||||
|
||||
function formatPrice(value: number | null, curr: string) {
|
||||
if (value == null) return '—';
|
||||
return formatMoney(value, curr);
|
||||
}
|
||||
|
||||
onMounted(load);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="page">
|
||||
<header class="page-head">
|
||||
<div>
|
||||
<p class="eyebrow">تنظیمات</p>
|
||||
<h1>محصولات و خدمات</h1>
|
||||
<p class="muted">کاتالوگ محصول برای افزودن به معاملات.</p>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<form class="form-card" @submit.prevent="createProduct">
|
||||
<h2>محصول جدید</h2>
|
||||
<div class="grid">
|
||||
<div class="field">
|
||||
<label for="p-name">نام</label>
|
||||
<input id="p-name" v-model="name" required placeholder="مثلاً لایسنس سازمانی" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="p-sku">کد / SKU</label>
|
||||
<input id="p-sku" v-model="sku" placeholder="اختیاری" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="p-price">قیمت واحد</label>
|
||||
<input id="p-price" v-model="unitPrice" type="number" min="0" step="1" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="p-currency">ارز</label>
|
||||
<select id="p-currency" v-model="currency">
|
||||
<option v-for="code in enabledCurrencies" :key="code" :value="code">
|
||||
{{ code }}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="field wide">
|
||||
<label for="p-desc">توضیح</label>
|
||||
<input id="p-desc" v-model="description" />
|
||||
</div>
|
||||
</div>
|
||||
<button class="btn" type="submit" :disabled="saving">
|
||||
{{ saving ? 'در حال ثبت…' : 'افزودن محصول' }}
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<p v-if="error" class="error">{{ error }}</p>
|
||||
<p v-if="loading" class="muted">در حال بارگذاری…</p>
|
||||
|
||||
<div v-else class="list">
|
||||
<article v-for="product in products" :key="product.id" class="row">
|
||||
<div>
|
||||
<strong>{{ product.name }}</strong>
|
||||
<p class="meta">
|
||||
{{ formatPrice(product.unitPrice, product.currency) }}
|
||||
<span v-if="product.sku"> · {{ product.sku }}</span>
|
||||
<span v-if="!product.isActive"> · غیرفعال</span>
|
||||
</p>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<button class="btn btn-ghost" type="button" @click="toggleActive(product)">
|
||||
{{ product.isActive ? 'غیرفعال' : 'فعال' }}
|
||||
</button>
|
||||
<button class="btn btn-danger" type="button" @click="removeProduct(product)">
|
||||
حذف
|
||||
</button>
|
||||
</div>
|
||||
</article>
|
||||
<p v-if="!products.length" class="muted">هنوز محصولی ثبت نشده است.</p>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.page {
|
||||
display: grid;
|
||||
gap: 1.1rem;
|
||||
max-width: 920px;
|
||||
}
|
||||
|
||||
.page-head h1 {
|
||||
margin: 0.2rem 0 0.35rem;
|
||||
font-size: 1.7rem;
|
||||
}
|
||||
|
||||
.eyebrow {
|
||||
margin: 0;
|
||||
color: var(--accent);
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.muted {
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.form-card,
|
||||
.row {
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: var(--radius);
|
||||
box-shadow: var(--shadow);
|
||||
padding: 1.1rem;
|
||||
}
|
||||
|
||||
.form-card {
|
||||
display: grid;
|
||||
gap: 0.9rem;
|
||||
}
|
||||
|
||||
.form-card h2 {
|
||||
margin: 0;
|
||||
font-size: 1.05rem;
|
||||
}
|
||||
|
||||
.grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 0.85rem;
|
||||
}
|
||||
|
||||
.wide {
|
||||
grid-column: 1 / -1;
|
||||
}
|
||||
|
||||
input {
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 12px;
|
||||
padding: 0.8rem 0.95rem;
|
||||
background: #fff;
|
||||
font: inherit;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.list {
|
||||
display: grid;
|
||||
gap: 0.7rem;
|
||||
}
|
||||
|
||||
.row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.meta {
|
||||
margin: 0.25rem 0 0;
|
||||
color: var(--muted);
|
||||
font-size: 0.92rem;
|
||||
}
|
||||
|
||||
.actions {
|
||||
display: flex;
|
||||
gap: 0.45rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
@media (max-width: 700px) {
|
||||
.grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.row {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user