Skip to content

Commit

Permalink
feat: add (get table data & delete table row & reusable schemas) (#710)
Browse files Browse the repository at this point in the history
  • Loading branch information
yusualhashash authored Oct 3, 2024
2 parents 95487a6 + 30eda65 commit 9bc26c1
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 1 deletion.
50 changes: 50 additions & 0 deletions apps/web/src/table/form-schemas.ts
Original file line number Diff line number Diff line change
@@ -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,
);
28 changes: 28 additions & 0 deletions apps/web/src/table/table-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { GlobalFetch } from "src/fetch";

export async function getTableData<T>(
fetchLink: string,
page: number,
filter?: string,
) {
const url = `${fetchLink}?page=${page}&filter=${filter}`;
const data = await GlobalFetch<T>({
url,
showSuccessToast: false,
});
return data;
}
export async function deleteTableRow<T>(
fetchLink: string,
row: { id: string },
) {
const data = await GlobalFetch<T>({
url: fetchLink,
options: {
method: "DELETE",
body: JSON.stringify(row.id),
},
showSuccessToast: true,
});
return data;
}
3 changes: 2 additions & 1 deletion apps/web/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
}
Expand Down

0 comments on commit 9bc26c1

Please sign in to comment.