Fix RTL chart ordering with Y-axis and hover values; aggregate website views; refine category picker tree borders and spacing; add one-click FA→EN name translation on add product. Co-authored-by: Cursor <cursoragent@cursor.com>
56 lines
1.5 KiB
TypeScript
56 lines
1.5 KiB
TypeScript
import { apiRequest } from '../lib/api'
|
|
import { getActiveBusinessId } from '../lib/businessContext'
|
|
import type { ProductApi } from './productService'
|
|
|
|
export type ProductAiLanguage = 'en' | 'fa'
|
|
|
|
export type ProductAiFillField = 'summary' | 'description' | 'nameEn'
|
|
export type ProductAiPromptField = Extract<ProductAiFillField, 'summary' | 'description'>
|
|
|
|
export interface CreateProductByAiPayload {
|
|
categoryId: string
|
|
name: string
|
|
language: ProductAiLanguage
|
|
}
|
|
|
|
export interface FillProductFieldByAiPayload {
|
|
field: ProductAiFillField
|
|
prompt?: string
|
|
title?: string
|
|
nameFa?: string
|
|
categoryId?: string
|
|
}
|
|
|
|
export async function createProductByAi(payload: CreateProductByAiPayload) {
|
|
const businessId = getActiveBusinessId()
|
|
if (!businessId) {
|
|
throw new Error('No active business selected. Please sign in again.')
|
|
}
|
|
|
|
return apiRequest<{ message: string; product: ProductApi }>(
|
|
`/businesses/${businessId}/products/ai-create`,
|
|
{
|
|
method: 'POST',
|
|
auth: true,
|
|
body: payload,
|
|
},
|
|
)
|
|
}
|
|
|
|
export async function fillProductFieldByAi(payload: FillProductFieldByAiPayload) {
|
|
const businessId = getActiveBusinessId()
|
|
if (!businessId) {
|
|
throw new Error('No active business selected. Please sign in again.')
|
|
}
|
|
|
|
return apiRequest<
|
|
| { field: 'summary'; text: string }
|
|
| { field: 'description'; html: string }
|
|
| { field: 'nameEn'; text: string }
|
|
>(`/businesses/${businessId}/products/ai-fill`, {
|
|
method: 'POST',
|
|
auth: true,
|
|
body: payload,
|
|
})
|
|
}
|