-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add (get table data & delete table row & reusable schemas) (#710)
- Loading branch information
Showing
3 changed files
with
80 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters