diff --git a/apps/web/src/table/form-schemas.ts b/apps/web/src/table/form-schemas.ts new file mode 100644 index 000000000..29c8c0d1c --- /dev/null +++ b/apps/web/src/table/form-schemas.ts @@ -0,0 +1,50 @@ +import { + $UniRefund_CRMService_AddressTypes_UpdateAddressTypeDto, + $UniRefund_CRMService_EmailCommonDatas_UpdateEmailCommonDataDto, + $UniRefund_CRMService_Organizations_UpdateOrganizationDto, + $UniRefund_CRMService_TelephoneTypes_UpdateTelephoneTypeDto, +} from "@ayasofyazilim/saas/CRMService"; +import { createZodObject } from "@repo/ayasofyazilim-ui/lib/create-zod-object"; + +// re-usable shorter imports +export const UpdateOrganizationDto = + $UniRefund_CRMService_Organizations_UpdateOrganizationDto; +export const UpdateTelephoneTypeDto = + $UniRefund_CRMService_TelephoneTypes_UpdateTelephoneTypeDto; +export const UpdateAddressTypeDto = + $UniRefund_CRMService_AddressTypes_UpdateAddressTypeDto; +export const UpdateEmailCommonDataDto = + $UniRefund_CRMService_EmailCommonDatas_UpdateEmailCommonDataDto; + +// re-usable schema sub-positions to prevent repeated code +const TelephoneSubPosition = ["localNumber", "typeCode"]; +const AddressSubPosition = [ + "country", + "terriority", + "city", + "postalCode", + "addressLine", + "fullAddress", + "typeCode", +]; +const EmailSubPosition = ["emailAddress", "typeCode"]; +export const ContactFormSubPositions = { + telephone: TelephoneSubPosition, + address: AddressSubPosition, + email: EmailSubPosition, +}; + +// re-usable schemas to prevent repeated code +export const emailSchema = createZodObject( + UpdateEmailCommonDataDto, + ContactFormSubPositions.email, +); +export const telephoneSchema = createZodObject( + UpdateTelephoneTypeDto, + ContactFormSubPositions.telephone, +); + +export const addressSchema = createZodObject( + UpdateAddressTypeDto, + ContactFormSubPositions.address, +); diff --git a/apps/web/src/table/table-utils.ts b/apps/web/src/table/table-utils.ts new file mode 100644 index 000000000..2412b50b6 --- /dev/null +++ b/apps/web/src/table/table-utils.ts @@ -0,0 +1,28 @@ +import { GlobalFetch } from "src/fetch"; + +export async function getTableData( + fetchLink: string, + page: number, + filter?: string, +) { + const url = `${fetchLink}?page=${page}&filter=${filter}`; + const data = await GlobalFetch({ + url, + showSuccessToast: false, + }); + return data; +} +export async function deleteTableRow( + fetchLink: string, + row: { id: string }, +) { + const data = await GlobalFetch({ + url: fetchLink, + options: { + method: "DELETE", + body: JSON.stringify(row.id), + }, + showSuccessToast: true, + }); + return data; +} diff --git a/apps/web/src/utils.ts b/apps/web/src/utils.ts index 41655958a..838551da0 100644 --- a/apps/web/src/utils.ts +++ b/apps/web/src/utils.ts @@ -144,7 +144,8 @@ export interface TableData { createFormSchema?: FormModifier; editFormSchema?: FormModifier; tableSchema: FormModifier; - title?: string; + title?: string; //should be removed in future + translationKey?: string; // for translation purposes filterBy?: string; detailedFilters?: ColumnFilter[]; }