diff --git a/src/api/types.ts b/src/api/types.ts index a47a5db..e532299 100644 --- a/src/api/types.ts +++ b/src/api/types.ts @@ -109,6 +109,11 @@ export type UpdateUserPayload = { isActive?: boolean; }; +export type AdminSetUserPasswordPayload = { + password: string; + confirmPassword: string; +}; + export type AssignOwnerPayload = { mobile: string; fullName?: string | null; diff --git a/src/api/users.ts b/src/api/users.ts index 88298b9..2030bc6 100644 --- a/src/api/users.ts +++ b/src/api/users.ts @@ -1,5 +1,5 @@ import { api } from './client'; -import type { UpdateUserPayload, User } from './types'; +import type { AdminSetUserPasswordPayload, UpdateUserPayload, User } from './types'; export function fetchUsers() { return api('/users'); @@ -15,3 +15,10 @@ export function updateUser(id: string, payload: UpdateUserPayload) { body: JSON.stringify(payload), }); } + +export function setUserPassword(id: string, payload: AdminSetUserPasswordPayload) { + return api(`/users/${id}/password`, { + method: 'PATCH', + body: JSON.stringify(payload), + }); +} diff --git a/src/components/admin/BusinessServicesSection.vue b/src/components/admin/BusinessServicesSection.vue index 35c8314..da01ec9 100644 --- a/src/components/admin/BusinessServicesSection.vue +++ b/src/components/admin/BusinessServicesSection.vue @@ -130,9 +130,18 @@ async function load() { } } +function parsePrice(value: string | number): number | null { + if (value === '' || value == null) return null; + if (typeof value === 'number') { + return Number.isFinite(value) && value >= 0 ? value : null; + } + const n = Number.parseFloat(String(value).replace(/,/g, '').trim()); + return Number.isFinite(n) && n >= 0 ? n : null; +} + async function onAdd() { - const price = Number.parseFloat(form.value.price.replace(/,/g, '')); - if (!form.value.serviceTemplateId || !Number.isFinite(price) || price < 0) { + const price = parsePrice(form.value.price); + if (!form.value.serviceTemplateId || price === null) { error.value = 'نوع خدمت و قیمت معتبر را وارد کنید.'; return; } diff --git a/src/views/UsersView.vue b/src/views/UsersView.vue index 9e3b723..fc41301 100644 --- a/src/views/UsersView.vue +++ b/src/views/UsersView.vue @@ -37,6 +37,9 @@ {{ activeLabel(user.isActive) }} + + {{ user.hasPassword ? 'رمز دارد' : 'بدون رمز' }} + @@ -64,6 +67,31 @@ حساب فعال است +
+

+ {{ editing.hasPassword ? 'تغییر رمز عبور' : 'تنظیم رمز عبور' }} +

+

+ اختیاری — در صورت پر کردن، رمز کاربر بدون نیاز به رمز قبلی تنظیم می‌شود. +

+ + +
+ ذخیره @@ -72,7 +100,7 @@