diff --git a/apps/web/src/app/[lang]/app/actions/CrmService/actions.ts b/apps/web/src/app/[lang]/app/actions/CrmService/actions.ts index 38ecd11eb..62eb7ef02 100644 --- a/apps/web/src/app/[lang]/app/actions/CrmService/actions.ts +++ b/apps/web/src/app/[lang]/app/actions/CrmService/actions.ts @@ -1,3 +1,4 @@ +"use server"; import type { GetApiCrmServiceMerchantsData, GetApiCrmServiceTaxOfficesData, diff --git a/packages/ayasofyazilim-ui b/packages/ayasofyazilim-ui index 6ae5c3a34..cb768ecd4 160000 --- a/packages/ayasofyazilim-ui +++ b/packages/ayasofyazilim-ui @@ -1 +1 @@ -Subproject commit 6ae5c3a341550136fcc5ad24914a932b2088addc +Subproject commit cb768ecd45817ff11e8299fd392079bad95888ef diff --git a/packages/ui/src/TableComponent/index.tsx b/packages/ui/src/TableComponent/index.tsx index c7391272b..4b7719dd7 100644 --- a/packages/ui/src/TableComponent/index.tsx +++ b/packages/ui/src/TableComponent/index.tsx @@ -6,10 +6,12 @@ import type { FilterColumnResult, TableAction, } from "@repo/ayasofyazilim-ui/molecules/tables"; +import { AutoFormProps } from "@repo/ayasofyazilim-ui/organisms/auto-form"; import Dashboard from "@repo/ayasofyazilim-ui/templates/dashboard"; import type { FormModifier } from "@repo/ui/utils/table/table-utils"; import { AUTO_COLUMNS_DATA, + convertZod, DELETE_ROW_ACTION, EDIT_ROW_ON_NEW_PAGE, TableAction_CREATE_ROW_ON_NEW_PAGE, @@ -18,6 +20,23 @@ import { import { useRouter } from "next/navigation"; import { useState } from "react"; +type CustomDialogItem = { + type: "row" | "table"; + title: string; + content: JSX.Element; +}; + +type AutoFormDialogItem = Pick< + AutoFormProps, + "values" | "dependencies" | "fieldConfig" +> & { + type: "row" | "table"; + title: string; + formPositions?: string[]; + onCallback: (row: any, values: unknown) => void; + schema: FormModifier; +}; + export default function TableComponent({ fetchRequest, deleteRequest, @@ -29,6 +48,8 @@ export default function TableComponent({ editOnNewPage, editOnNewPageUrl, detailedFilter, + customDialog, + autoFormDialog, languageData, }: { tableSchema: FormModifier; @@ -38,6 +59,8 @@ export default function TableComponent({ createOnNewPageUrl?: string; createOnNewPageTitle?: string; editOnNewPageUrl?: string; + customDialog?: CustomDialogItem[]; + autoFormDialog?: AutoFormDialogItem[]; detailedFilter?: ColumnFilter[]; fetchRequest: ( page: number, @@ -76,6 +99,7 @@ export default function TableComponent({ toast.error(languageData["Fetch.Fail"]); }); } + function deleteRow(row: { id: string }) { if (!deleteRequest) return; setIsLoading(true); @@ -129,6 +153,50 @@ export default function TableComponent({ ); } + if (customDialog) { + customDialog.forEach((dialog) => { + const _action: TableAction = { + type: "Dialog", + cta: dialog.title, + loadingContent: <>{languageData.Loading}, + description: dialog.title, + componentType: "CustomComponent", + content: dialog.content, + }; + if (dialog.type === "row") { + columnsData.data.actionList?.push(_action); + return; + } + action?.push(_action); + }); + } + if (autoFormDialog) { + autoFormDialog.forEach((dialog) => { + const formSchema = convertZod(dialog.schema); + const _action: TableAction = { + cta: dialog.title, + description: dialog.title, + type: "Dialog", + componentType: "Autoform", + autoFormArgs: { + ...dialog, + formSchema, + submit: { + cta: languageData["Save"], + }, + }, + callback: (data, row) => { + dialog.onCallback(data, row); + }, + }; + if (dialog.type === "row") { + columnsData.data.actionList?.push(_action); + return; + } + action?.push(_action); + }); + } + return ( item.id === value)?.name || ""; } + +export function convertZod(schema: FormModifier) { + const newSchema = createZodObject( + schema.schema, + schema.formPositions || [], + schema.convertors || {}, + ); + return newSchema; +}