feat: add logo field to settings schema and update settings client to handle file uploads
feat: integrate dialog close context in vendor select field and CRUD dialog components feat: enhance vendor general info to format status using utility function feat: implement form dialog context for managing dialog close actions feat: add async select field dialog close context for better form handling fix: update form mutation hook to close dialog on successful submission feat: extend document print types to include expense and credit note feat: add settings update payload type to include logo and other fields feat: create employee attendance and work history pages with resource management feat: implement payment made and received detail pages with actions feat: add quick shortcuts component for easy navigation in the dashboard feat: create actions for payment made and received with print and delete options feat: implement dialog close context for better dialog management feat: add error parsing utility for improved error handling in API responses
This commit is contained in:
@@ -11,9 +11,11 @@ export type DocumentPrintType =
|
||||
| "job_card"
|
||||
| "invoice"
|
||||
| "payment_received"
|
||||
| "expense"
|
||||
| "purchase_order"
|
||||
| "bill"
|
||||
| string
|
||||
| "payment_made"
|
||||
| "credit_note"
|
||||
|
||||
export type DocumentPrintMode = "print" | "download"
|
||||
|
||||
|
||||
@@ -1,10 +1,34 @@
|
||||
import { ApiClient, type ApiClientOptions } from "../infra/client"
|
||||
import type { ApiPath, ApiRequestBody } from "../infra/types"
|
||||
import type { ApiPath } from "../infra/types"
|
||||
|
||||
export const SETTINGS_ROUTES = {
|
||||
INDEX: "/api/settings",
|
||||
} as const satisfies Record<string, ApiPath>
|
||||
|
||||
export type SettingsUpdatePayload = {
|
||||
name?: string
|
||||
email?: string
|
||||
phone?: string
|
||||
alternative_phone?: string
|
||||
website?: string
|
||||
time_zone?: string
|
||||
upi_id?: string
|
||||
first_day_of_work?: string
|
||||
latitude?: string | number
|
||||
longitude?: string | number
|
||||
bank_details?: string
|
||||
first_address_line?: string
|
||||
second_address_line?: string
|
||||
country_id?: number | string
|
||||
state_id?: number | string
|
||||
city?: string
|
||||
zip_code?: string
|
||||
description?: string
|
||||
security?: string
|
||||
privacy_policy?: string
|
||||
logo?: File | null
|
||||
}
|
||||
|
||||
export class SettingsClient extends ApiClient {
|
||||
constructor(baseUrl?: string, defaultOptions?: ApiClientOptions) {
|
||||
super(baseUrl, defaultOptions)
|
||||
@@ -14,7 +38,23 @@ export class SettingsClient extends ApiClient {
|
||||
return this.get(SETTINGS_ROUTES.INDEX)
|
||||
}
|
||||
|
||||
async update(payload: ApiRequestBody<typeof SETTINGS_ROUTES.INDEX, "put">) {
|
||||
return this.put(SETTINGS_ROUTES.INDEX, payload)
|
||||
async update(payload: SettingsUpdatePayload) {
|
||||
const hasFile = payload && (payload as any).logo instanceof File
|
||||
if (!hasFile) {
|
||||
const { logo: _logo, ...rest } = (payload ?? {}) as Record<string, unknown>
|
||||
return this.put(SETTINGS_ROUTES.INDEX, rest as any)
|
||||
}
|
||||
|
||||
const fd = new FormData()
|
||||
for (const [key, value] of Object.entries(payload as Record<string, unknown>)) {
|
||||
if (value === undefined || value === null) continue
|
||||
if (value instanceof File) {
|
||||
fd.append(key, value)
|
||||
} else {
|
||||
fd.append(key, String(value))
|
||||
}
|
||||
}
|
||||
fd.append("_method", "PUT")
|
||||
return this.postFormData(SETTINGS_ROUTES.INDEX, fd)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,4 +19,5 @@ export {
|
||||
export { ApiClient, ApiError, type ApiClientOptions } from "./client"
|
||||
export { DEFAULT_PER_PAGE } from "./crud-client"
|
||||
export * from "./crud-client"
|
||||
export { parseApiError } from "./parse-error"
|
||||
export type { AuthUser } from "./token"
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import { ApiError } from "./client"
|
||||
|
||||
/**
|
||||
* Extract a user-facing error message from a thrown ApiError (or any unknown error).
|
||||
* Order: first Laravel field error → payload.message → error.message → fallback.
|
||||
*/
|
||||
export function parseApiError(error: unknown, fallback = "Request failed"): string {
|
||||
const e = error as { payload?: { errors?: unknown; message?: string }; message?: string } | undefined
|
||||
if (!e) return fallback
|
||||
|
||||
const errors = e.payload?.errors
|
||||
if (errors && typeof errors === "object" && !Array.isArray(errors)) {
|
||||
const first = Object.values(errors as Record<string, unknown>)[0]
|
||||
if (Array.isArray(first) && typeof first[0] === "string") {
|
||||
return first[0]
|
||||
}
|
||||
if (typeof first === "string") {
|
||||
return first
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof e.payload?.message === "string" && e.payload.message.length > 0) {
|
||||
return e.payload.message
|
||||
}
|
||||
|
||||
if (error instanceof ApiError && error.message) {
|
||||
return error.message
|
||||
}
|
||||
|
||||
if (typeof e.message === "string" && e.message.length > 0) {
|
||||
return e.message
|
||||
}
|
||||
|
||||
return fallback
|
||||
}
|
||||
Reference in New Issue
Block a user