This commit is contained in:
2026-09-19 16:59:15 +03:30
parent 663d0a36aa
commit 0d113611cb
198 changed files with 2491 additions and 944 deletions
+1 -1
View File
@@ -108,7 +108,7 @@ export const useAuthStore = defineStore('auth', () => {
}
async function updateProfile(
data: Partial<Pick<User, 'firstName' | 'lastName' | 'nationalId' | 'avatarUrl'>>,
data: Partial<Pick<User, 'firstName' | 'lastName' | 'nationalId' | 'avatarUrl' | 'address'>>,
) {
if (!user.value) return null
const updated = await authUpdateProfile(data)
+24 -5
View File
@@ -192,6 +192,8 @@ export const useCartStore = defineStore('cart', () => {
catalogCode: string,
meterage: number,
company: Company,
notes?: string,
accumulate = false,
): { success: boolean; message?: string } {
const cart = getOrCreateCart(company)
const existing = cart.items.find((i) => i.productId === product.id)
@@ -199,7 +201,16 @@ export const useCartStore = defineStore('cart', () => {
if (existing) {
const index = items.findIndex((i) => i.id === existing.id)
items[index] = { ...existing, meterage }
const mergedNotes = notes
? [existing.notes, notes].filter(Boolean).join(' | ')
: existing.notes
const nextMeterage = accumulate ? existing.meterage + meterage : meterage
items[index] = {
...existing,
meterage: nextMeterage,
color: product.color || existing.color,
notes: mergedNotes || undefined,
}
} else {
const item: CartItem = {
id: `local-item-${product.id}-${Date.now()}`,
@@ -209,6 +220,7 @@ export const useCartStore = defineStore('cart', () => {
productCode: product.code,
color: product.color,
meterage,
notes: notes || undefined,
companyId: company.id,
companyName: company.name,
}
@@ -230,6 +242,8 @@ export const useCartStore = defineStore('cart', () => {
product: Product,
catalogCode: string,
meterage: number,
notes?: string,
accumulate = false,
): Promise<{ success: boolean; message?: string }> {
if (!catalogStore.companies.length) {
await catalogStore.loadCompanies()
@@ -242,9 +256,11 @@ export const useCartStore = defineStore('cart', () => {
: 0
const existing = cart.items.find((i) => i.productId === product.id)
const previousMeterage = existing?.meterage ?? 0
const nextMeterage =
existing && accumulate ? previousMeterage + meterage : meterage
const validation = validateMeterage(
meterage,
nextMeterage,
product,
currentCompanyMeterage,
companyMax,
@@ -258,20 +274,23 @@ export const useCartStore = defineStore('cart', () => {
if (!company) {
return { success: false, message: 'شرکت محصول یافت نشد.' }
}
return addItemLocal(product, catalogCode, meterage, company)
return addItemLocal(product, catalogCode, meterage, company, notes, accumulate)
}
try {
let serverCart: ApiCart
const mergedNotes = notes
? [existing?.notes, notes].filter(Boolean).join(' | ')
: existing?.notes
if (existing) {
serverCart = await apiRequest<ApiCart>(`/carts/items/${existing.id}`, {
method: 'PATCH',
body: { meterage },
body: { meterage: nextMeterage, notes: mergedNotes || undefined },
})
} else {
serverCart = await apiRequest<ApiCart>('/carts/items', {
method: 'POST',
body: { productId: product.id, meterage },
body: { productId: product.id, meterage: nextMeterage, notes: notes || undefined },
})
}
applyServerCart(serverCart)
+8
View File
@@ -27,7 +27,10 @@ export type CatalogRequestStatus =
export type CatalogRequest = {
id: string
createdAt: string
updatedAt?: string
status: CatalogRequestStatus
/** Raw status from API for timeline mapping */
serverStatus?: string
note?: string
items: CatalogRequestItem[]
}
@@ -72,6 +75,7 @@ const STATUS_LABELS: Record<string, string> = {
function mapServerRow(row: {
id: string
createdAt: string
updatedAt?: string
status: string
note?: string
items: Array<{
@@ -84,7 +88,9 @@ function mapServerRow(row: {
return {
id: row.id,
createdAt: row.createdAt,
updatedAt: row.updatedAt,
status: SERVER_TO_UI[row.status] ?? (row.status as CatalogRequestStatus),
serverStatus: row.status,
note: row.note,
items: row.items.map((i) => ({
productId: i.productId,
@@ -117,6 +123,7 @@ export const useCatalogRequestsStore = defineStore('catalogRequests', () => {
Array<{
id: string
createdAt: string
updatedAt?: string
status: string
note?: string
items: Array<{
@@ -151,6 +158,7 @@ export const useCatalogRequestsStore = defineStore('catalogRequests', () => {
const row = await apiRequest<{
id: string
createdAt: string
updatedAt?: string
status: string
note?: string
items: Array<{