Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ertugrulcan-ays authored Oct 21, 2024
2 parents 6d179c2 + eb25448 commit 91f6014
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 1 deletion.
1 change: 1 addition & 0 deletions apps/web/src/app/[lang]/app/actions/CrmService/actions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"use server";
import type {
GetApiCrmServiceMerchantsData,
GetApiCrmServiceTaxOfficesData,
Expand Down
2 changes: 1 addition & 1 deletion packages/ayasofyazilim-ui
68 changes: 68 additions & 0 deletions packages/ui/src/TableComponent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -29,6 +48,8 @@ export default function TableComponent({
editOnNewPage,
editOnNewPageUrl,
detailedFilter,
customDialog,
autoFormDialog,
languageData,
}: {
tableSchema: FormModifier;
Expand All @@ -38,6 +59,8 @@ export default function TableComponent({
createOnNewPageUrl?: string;
createOnNewPageTitle?: string;
editOnNewPageUrl?: string;
customDialog?: CustomDialogItem[];
autoFormDialog?: AutoFormDialogItem[];
detailedFilter?: ColumnFilter[];
fetchRequest: (
page: number,
Expand Down Expand Up @@ -76,6 +99,7 @@ export default function TableComponent({
toast.error(languageData["Fetch.Fail"]);
});
}

function deleteRow(row: { id: string }) {
if (!deleteRequest) return;
setIsLoading(true);
Expand Down Expand Up @@ -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 (
<Dashboard
action={action}
Expand Down
10 changes: 10 additions & 0 deletions packages/ui/utils/table/table-utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { toast } from "@repo/ayasofyazilim-ui/atoms/sonner";
import { createZodObject } from "@repo/ayasofyazilim-ui/lib/create-zod-object";
import jsonToCsv from "@repo/ayasofyazilim-ui/lib/json-to-csv";
import type {
ColumnFilter,
Expand Down Expand Up @@ -148,3 +149,12 @@ export function getEnumName(
) {
return data?.find((item) => item.id === value)?.name || "";
}

export function convertZod(schema: FormModifier) {
const newSchema = createZodObject(
schema.schema,
schema.formPositions || [],
schema.convertors || {},
);
return newSchema;
}

0 comments on commit 91f6014

Please sign in to comment.