diff --git a/src/(apicalls)/basics.ts b/src/(apicalls)/basics.ts index 719dcd7..f725a36 100644 --- a/src/(apicalls)/basics.ts +++ b/src/(apicalls)/basics.ts @@ -4,44 +4,44 @@ export const tokenSecret = export const cookieObject: any = { httpOnly: true, path: "/", - // secure: true, sameSite: "strict", maxAge: 3600, }; interface FilterListInterface { - page?: number; - size?: number; - order_field?: string; - order_type?: string; - include_joins?: any[]; - query?: any; + page?: number | null | undefined; + size?: number | null | undefined; + orderField?: string | null | undefined; + orderType?: string | null | undefined; + includeJoins?: any[] | null | undefined; + query?: any | null | undefined; } class FilterList { page?: number = 1; size?: number = 5; - order_field?: string = "id"; - order_type?: string = "asc"; - include_joins?: any[] = []; - + orderField?: string = "id"; + orderType?: string = "asc"; + includeJoins?: any[] = []; query?: any; constructor({ - page, - size, - order_field, - order_type, - include_joins, - query, + page: page = 1, + size: size = 5, + orderField: orderField = "asc", + orderType: orderType = "id", + includeJoins: includeJoins = [], + query: query = {}, }: FilterListInterface) { this.page = page || 1; this.size = size || 5; - this.order_field = order_field || "id"; - this.order_type = order_type || "asc"; - this.include_joins = include_joins || []; + this.orderField = orderField || "id"; + this.orderType = orderType || "asc"; + this.includeJoins = includeJoins || []; this.query = query || {}; } } -export { FilterList }; +const defaultFilterList = new FilterList({}); + +export { FilterList, defaultFilterList }; export type { FilterListInterface }; diff --git a/src/(apicalls)/building/build.tsx b/src/(apicalls)/building/build.tsx index bfb7bbc..92292b5 100644 --- a/src/(apicalls)/building/build.tsx +++ b/src/(apicalls)/building/build.tsx @@ -1,14 +1,18 @@ "use server"; -import { fetchData, fetchDataWithToken } from "../api-fetcher"; -import { baseUrl, FilterList, FilterListInterface } from "../basics"; +import { fetchDataWithToken } from "../api-fetcher"; +import { + baseUrl, + FilterList, + FilterListInterface, + defaultFilterList, +} from "../basics"; const buildListEndpoint = `${baseUrl}/building/build/list`; async function retrieveBuildList(payload: FilterListInterface) { - const feedObject = new FilterList(payload); const tokenResponse: any = await fetchDataWithToken( buildListEndpoint, - feedObject, + new FilterList(payload || defaultFilterList), "POST", false ); diff --git a/src/(apicalls)/validations/validationProcesser.ts b/src/(apicalls)/validations/validationProcesser.ts index 84b2522..3a87f30 100644 --- a/src/(apicalls)/validations/validationProcesser.ts +++ b/src/(apicalls)/validations/validationProcesser.ts @@ -34,17 +34,15 @@ class HeadersAndValidations { } parseProcesser() { - const requiredKeys = Array.from(this.validation?.required); Object.entries(this.properties).map(([key, value]) => { - const isRequired: Boolean = requiredKeys.includes(key); - const multipleTypes: Object[] = value?.anyOf; + const multipleTypes: Object[] = value?.anyOf || []; + const isRequired: boolean = Object.keys(value).includes("anyOf"); if (!isRequired) { multipleTypes.map((row: any) => { if (row.type !== "null") { this.validated[key] = { required: false, fieldType: row.type, - // fieldType: this.parseType(row.type), }; } }); @@ -52,7 +50,6 @@ class HeadersAndValidations { this.validated[key] = { required: true, fieldType: value, - // fieldType: this.parseType(value), }; } }); diff --git a/src/(apicalls)/validations/validations.tsx b/src/(apicalls)/validations/validations.tsx index 11f9e04..f2a386d 100644 --- a/src/(apicalls)/validations/validations.tsx +++ b/src/(apicalls)/validations/validations.tsx @@ -45,10 +45,8 @@ async function retrieveHeadersAndValidationByEndpoint({ "POST", false ); - console.log("selectResponse", selectResponse); if (selectResponse.status === 200) { const responseParsed = new HeadersAndValidations(selectResponse); - console.log("responseParsed", responseParsed); return { status: selectResponse.status, headers: responseParsed.headers, @@ -60,7 +58,7 @@ async function retrieveHeadersAndValidationByEndpoint({ return { status: selectResponse.status, message: selectResponse.message, - + headers: null, validated: null, }; diff --git a/src/app/dashboard/page.tsx b/src/app/dashboard/page.tsx index 1a28dd7..aff0ebc 100644 --- a/src/app/dashboard/page.tsx +++ b/src/app/dashboard/page.tsx @@ -17,8 +17,6 @@ const Dashboard: React.FC = async () => { const eventsList = await retrieveAvailableEvents(); const availableMenu = retrieveAvailableCategories(eventsList || []); - - return ( <> diff --git a/src/app/trybuildpage/page.tsx b/src/app/trybuildpage/page.tsx new file mode 100644 index 0000000..bceccdf --- /dev/null +++ b/src/app/trybuildpage/page.tsx @@ -0,0 +1,31 @@ +"use server"; +import React from "react"; +import { redirect } from "next/navigation"; +import { + checkAccessTokenIsValid, + retrieveAvailableEvents, +} from "@/(apicalls)/cookies/token"; +import DashboardPage from "@/components/Dashboards/DashboardPage"; +import { retrieveAvailableCategories } from "@/appEvents/categories"; +import CreatePage from "@/components/ContextComponents/Commons/PageCreate"; + +const Dashboard: React.FC = async () => { + const token_is_valid = await checkAccessTokenIsValid(); + + if (!token_is_valid) { + redirect("/login/email"); + } + const eventsList = await retrieveAvailableEvents(); + const availableMenu = retrieveAvailableCategories(eventsList || []); + const pageInfo = { + title: "Bina Oluştur", + description: "Bina oluştur sayfasına hoş geldiniz", + }; + return ( + <> + + + ); +}; + +export default Dashboard; diff --git a/src/appEvents/categoriesSecond.ts b/src/appEvents/categoriesSecond.ts new file mode 100644 index 0000000..9b17041 --- /dev/null +++ b/src/appEvents/categoriesSecond.ts @@ -0,0 +1,182 @@ +import { + BuildIcon, + BuildPartIcon, + LivingSpaceIcon, + BuildAreaIcon, +} from "./building/iconSet"; +import { AccountIcon, meetingIcon } from "./account/iconSet"; +import { InviteIcon, TaskIcon } from "./decisionBook/iconSet"; + +import BuildPage from "./building/build"; +import BuildLivingSpacePage from "./building/livingspace"; +import AccountPage from "./account/account"; + +const BuildSubCategories = [ + { + title: "Daireler", + icon: BuildPartIcon, + component: BuildPage, + selfEndpoints: { + list: "/building/parts/list", + create: "/building/parts/create", + update: "/building/parts/update/{build_uu_id}", + }, + allEndpoints: [], + subCategories: [], + }, + { + title: "Kullanılabilir Alanlar", + icon: BuildAreaIcon, + component: BuildPage, + selfEndpoints: { + list: "/building/area/list", + create: "/building/area/create", + update: "/building/area/update/{build_uu_id}", + }, + allEndpoints: [], + subCategories: [], + }, + { + title: "Yaşayan Kişiler", + icon: LivingSpaceIcon, + component: BuildLivingSpacePage, + selfEndpoints: { + list: "/building/living_space/list", + create: "/building/living_space/create", + update: "/building/living_space/update/{build_uu_id}", + }, + allEndpoints: [], + subCategories: [], + }, +]; + +const AccountSubCategories = [ + { + title: "Bakiye Sorgulama", + icon: AccountIcon, + component: AccountPage, + selfEndpoints: { list: "/account/records/list" }, + allEndpoints: [], + subCategories: [], + }, +]; + +const DecisionBookSubCategories: any = []; + +const MeetingSubCategories = [ + { + title: "Davetiyeler", + icon: InviteIcon, + component: BuildPage, + selfEndpoints: { + list: "/build/decision_book/invite/list", + create: "/build/decision_book/invite/create", + update: "/build/decision_book/invite/update", + assign: "/build/decision_book/invitations/assign", + }, + allEndpoints: [], + subCategories: [], + }, + { + title: "Görev Ata", + icon: TaskIcon, + component: BuildPage, + selfEndpoints: {}, + allEndpoints: [], + subCategories: [], + }, +]; + +const buildAllEndpoints = [ + "/building/build/list", + "/building/build/create", + "/building/build/update/{build_uu_id}", + "/building/parts/list", + "/building/parts/create", + "/building/parts/update/{build_uu_id}", + "/building/area/list", + "/building/area/create", + "/building/area/update/{build_uu_id}", + "/building/living_space/list", + "/building/living_space/create", + "/building/living_space/update/{build_uu_id}", +]; + +const meetingAllEndpoints = [ + "/build/decision_book/invite/list", + "/build/decision_book/invite/create", + "/build/decision_book/invite/update", + "/build/decision_book/invitations/assign", +]; + +const accountAllEndpoints = ["/account/records/list"]; + +const LeftMenuCategories = [ + { + title: "Bina Tanımları", + icon: BuildIcon, + component: BuildPage, + allEndpoints: buildAllEndpoints, + selfEndpoints: { + list: "/building/build/list", + create: "/building/build/create", + update: "/building/build/update/{build_uu_id}", + }, + subCategories: BuildSubCategories, + }, + { + title: "Toplantılar", + icon: meetingIcon, + allEndpoints: meetingAllEndpoints, + component: BuildPage, + selfEndpoints: {}, + subCategories: MeetingSubCategories, + }, + { + title: "Cari Hesaplar", + icon: AccountIcon, + component: BuildPage, + selfEndpoints: {}, + allEndpoints: accountAllEndpoints, + subCategories: AccountSubCategories, + }, + { + title: "Karar Defteri", + icon: "decision", + component: BuildPage, + selfEndpoints: {}, + allEndpoints: [], + subCategories: DecisionBookSubCategories, + }, +]; + +export function retrieveAvailableCategories(availableCategories: any) { + const availableCategoriesList = Array.from( + availableCategories?.availableEvents || [] + ); + let availableMenu: Array = []; + + for (let i = 0; i < LeftMenuCategories.length; i++) { + const category = LeftMenuCategories[i]; + if (category.allEndpoints) { + const setCategory = isCategoryAvailable( + category, + availableCategoriesList + ); + if (setCategory) { + availableMenu.push(category); + } + } + } + return availableMenu; +} + +function isCategoryAvailable(category: any, availableCategoriesList: any) { + const categoryList = Array.from(category.allEndpoints); + for (let j = 0; j < categoryList.length; j++) { + const endpoint = categoryList[j]; + if (availableCategoriesList.includes(endpoint)) { + return true; + } + } +} diff --git a/src/components/ContextComponents/Building/Build/Build.tsx b/src/components/ContextComponents/Building/Build/Build.tsx index aa79bb1..c7ecc09 100644 --- a/src/components/ContextComponents/Building/Build/Build.tsx +++ b/src/components/ContextComponents/Building/Build/Build.tsx @@ -6,161 +6,99 @@ import IsNotAllowed from "@/components/ContextComponents/Commons/PageisNotAllowe import DeleteButton from "@/components/ContextComponents/Commons/ButtonDelete"; import UpdateButton from "@/components/ContextComponents/Commons/ButtonUpdate"; import CreateButton from "@/components/ContextComponents/Commons/ButtonCreate"; -import BuildUpdatePage from "@/components/ContextComponents/Building/Build/BuildUpdate"; - import { retrieveAvailableEvents } from "@/(apicalls)/cookies/token"; import { retrieveBuildList, updateBuild, createBuild, } from "@/(apicalls)/building/build"; -import { - retrieveHeadersEndpoint, - retrieveHeadersAndValidationByEndpoint, -} from "@/(apicalls)/validations/validations"; -import PageCreate from "../../Commons/PageCreate"; +import CreatePage from "@/components/ContextComponents/Commons/PageCreate"; +import DashPage from "@/components/ContextComponents/Commons/DashPage"; +import PageUpdate from "@/components/ContextComponents/Commons/PageUpdate"; const Build: React.FC = () => { - const [renderTable, setRenderTable] = React.useState(false); - const [renderCreate, setRenderCreate] = React.useState(false); - const [renderUpdate, setRenderUpdate] = React.useState(false); - const [renderDelete, setRenderDelete] = React.useState(false); - const [isFormEnabled, setIsFormEnabled] = React.useState(false); - const [formPage, setFormPage] = React.useState(); - const [createValidation, setCreateValidation] = React.useState({}); - const [updateValidation, setUpdateValidation] = React.useState({}); - const [deleteValidation, setDeleteValidation] = React.useState({}); - const [tableValidation, setTableValidation] = React.useState([]); - const [tableHeaders, setTableHeaders] = React.useState({}); - const [tableSelectedRow, setTableSelectedRow] = React.useState({}); + const [formPage, setFormPage]: [any, any] = React.useState(null); + const [endpointNeedsList, setEndpointNeedsList] = React.useState({}); const endpointNeeds = { table: { endpoint: "/building/build/list", - variableKey: "headers", - variableReact: setTableHeaders, - component: renderTable ? ( + component: ( setFormPage(null)} + updatePageInfo={{ + title: "Bina Güncelle", + description: "Bina güncelleme sayfasına hoş geldiniz", + }} /> - ) : ( - - ), - isRender: setRenderTable, - }, - update: { - endpoint: "/building/build/update", - isRender: setRenderUpdate, - variableReact: setUpdateValidation, - variableKey: "validation", - component: renderUpdate ? ( - - } - formPageFunction={setFormPage} - isFormEnabledFunction={setIsFormEnabled} - /> - ) : ( - ), + notAllowed: , }, create: { endpoint: "/building/build/create", - isRender: setRenderCreate, - variableReact: setCreateValidation, - variableKey: "validation", - component: renderCreate ? ( + component: ( console.log("Create button clicked")} - /> + setFormPage={() => + setFormPage( + setFormPage(null)} + /> + ) } - isFormEnabled={isFormEnabled} - formPageFunction={setFormPage} - isFormEnabledFunction={setIsFormEnabled} /> - ) : ( - + ), + notAllowed: ( + ), }, delete: { endpoint: "/building/build/delete", - variableKey: "headers", - variableReact: setDeleteValidation, - component: renderDelete ? ( - () => setIsFormEnabled(true)} /> - ) : ( - + component: () => console.log("Hi")} />, + notAllowed: ( + ), - isRender: setRenderDelete, }, }; React.useEffect(() => { retrieveAvailableEvents() .then((data) => { - for (const endpointNeed of Object.values(endpointNeeds)) { - if (data?.availableEvents.includes(endpointNeed.endpoint)) { - if (endpointNeed.variableKey === "headers") { - retrieveHeadersEndpoint({ endpoint: endpointNeed.endpoint }) - .then((validator) => { - if (JSON.stringify(validator?.headers) !== "{}") { - setTableHeaders(validator?.headers); - } - }) - .catch(() => {}); - } else if (endpointNeed.variableKey === "validation") { - retrieveHeadersAndValidationByEndpoint({ - endpoint: endpointNeed.endpoint, - }) - .then((validator) => { - if (JSON.stringify(validator?.validated) !== "{}") { - endpointNeed.variableReact(validator); - } - }) - .catch(() => {}); - } - endpointNeed.isRender(true); + for (const [key, component] of Object.entries(endpointNeeds)) { + if (data?.availableEvents.includes(component.endpoint)) { + setEndpointNeedsList((prev) => ({ + ...prev, + [key]: component.component, + })); + } else { + setEndpointNeedsList((prev) => ({ + ...prev, + [key]: component.notAllowed, + })); } } }) .catch(() => {}); - }, []); + }, [formPage]); return ( - <> - {isFormEnabled ? ( - formPage - ) : ( -
-
- {endpointNeeds.update.component} - {endpointNeeds.create.component} - {endpointNeeds.delete.component} -
- {endpointNeeds.table.component} -
- )} - + <>{formPage ? formPage : } ); }; diff --git a/src/components/ContextComponents/Building/Build/BuildCreate.tsx b/src/components/ContextComponents/Building/Build/BuildCreate.tsx new file mode 100644 index 0000000..d8f7bf6 --- /dev/null +++ b/src/components/ContextComponents/Building/Build/BuildCreate.tsx @@ -0,0 +1,213 @@ +"use client"; +import React from "react"; +import EventButton from "@/components/ContextComponents/Commons/ButtonEvent"; + +import { + Form, + FormControl, + FormDescription, + FormField, + FormItem, + FormLabel, + FormMessage, +} from "@/components/ui/form"; +import { z } from "zod"; +import { zodResolver } from "@hookform/resolvers/zod"; +import { useForm } from "react-hook-form"; +import { retrieveValidationsByEndpoint } from "../../functions/retrieveEndpointAndValidations"; + +interface BuildCreateProps { + pageInfo: any; + endpoint: string; +} + +const BuildCreate: React.FC = ({ pageInfo, endpoint }) => { + const [zodValidation, setZodValidation] = React.useState(z.object({})); + const [apiValidation, setApiValidation] = React.useState({}); + const [apiHeaders, setApiHeaders] = React.useState({}); + + React.useEffect(() => { + retrieveValidationsByEndpoint(endpoint).then((validations: any) => { + setZodValidation(validations.zodValidation as any); + setApiHeaders(validations.apiValidation?.headers as Object); + setApiValidation(validations.apiValidation?.validated as Object); + }); + }, []); + + const form = useForm>({ + resolver: zodResolver(zodValidation), + }); + + function closeFormPage() {} + function onClickAction() {} + + return ( +
+ <> +

{pageInfo.description}

+
+ closeFormPage()} + label="Dashboarda Dön" + bgColor="bg-red-700" + icon={ + + + + + + } + /> +
+ onClickAction()} + label="Kaydet" + bgColor="bg-emerald-700" + icon={ + + + + } + /> +
+
+ { +
+ + {Object.entries(apiValidation).map( + ([key, value]: [string, any]) => { + console.log("key", key); + const keyValidation = apiValidation[key] || { + fieldType: { type: "string" }, + required: false, + }; + const fieldType = keyValidation.fieldType?.type || "string"; + if (fieldType === "string" && apiHeaders[key]) { + return ( + <> +
+ +
+ ( + + + + + + + )} + /> + + + + + + +
+
+ + ); + } else if (fieldType === "integer" && apiHeaders[key]) { + return ( + <> +
+ +
+ ( + + + + + + + )} + /> + + + + + + +
+
+ + ); + } + } + )} + + + } + +
+ ); +}; + +export default BuildCreate; diff --git a/src/components/ContextComponents/Building/Build/BuildTable.tsx b/src/components/ContextComponents/Building/Build/BuildTable.tsx new file mode 100644 index 0000000..8a945cc --- /dev/null +++ b/src/components/ContextComponents/Building/Build/BuildTable.tsx @@ -0,0 +1,11 @@ +import React from 'react'; + +const BuildTable: React.FC = () => { + return ( +
+ {} +
+ ); +}; + +export default BuildTable; \ No newline at end of file diff --git a/src/components/ContextComponents/Building/Build/BuildUpdate.tsx b/src/components/ContextComponents/Building/Build/BuildUpdate.tsx index cfb5f36..d3ec4f0 100644 --- a/src/components/ContextComponents/Building/Build/BuildUpdate.tsx +++ b/src/components/ContextComponents/Building/Build/BuildUpdate.tsx @@ -1,23 +1,16 @@ import React from "react"; import PageUpdate from "@/components/ContextComponents/Commons/PageUpdate"; -import IsNotAllowed from "@/components/ContextComponents/Commons/PageisNotAllowed"; interface BuildUpdatePageButtonProps { - validation: any; - tableSelectedRow: any; - saveFunction: any; - setTableSelectedRow: React.Dispatch>; - formPageFunction: React.Dispatch>; - isFormEnabledFunction: React.Dispatch>; + endpoint: string; + pageInfo: any; + selectedRow: any; } const BuildUpdatePage: React.FC = ({ - validation, - tableSelectedRow, - saveFunction, - setTableSelectedRow, - formPageFunction, - isFormEnabledFunction, + endpoint, + pageInfo, + selectedRow, }) => { return (
@@ -28,7 +21,6 @@ const BuildUpdatePage: React.FC = ({ saveFunction={saveFunction} setTableSelectedRow={setTableSelectedRow} formPageFunction={formPageFunction} - isFormEnabledFunction={isFormEnabledFunction} />
); diff --git a/src/components/ContextComponents/Commons/ButtonCreate.tsx b/src/components/ContextComponents/Commons/ButtonCreate.tsx index 4e5b98b..c3ba311 100644 --- a/src/components/ContextComponents/Commons/ButtonCreate.tsx +++ b/src/components/ContextComponents/Commons/ButtonCreate.tsx @@ -3,47 +3,18 @@ import React from "react"; import EventButton from "@/components/ContextComponents/Commons/ButtonEvent"; interface CreateButtonProps { - + setFormPage: React.Dispatch>; buttonLabel: string; - pageToSet: any; - isFormEnabled: boolean; - formPageFunction: React.Dispatch>; - isFormEnabledFunction: React.Dispatch>; } const CreateButton: React.FC = ({ - - pageToSet, + setFormPage, buttonLabel, - isFormEnabled, - formPageFunction, - isFormEnabledFunction, }) => { - - function openFormPage({ - isFormEnabled, - setFormPage, - setIsFormEnabled, - }: { - isFormEnabled: boolean; - setFormPage: React.Dispatch>; - setIsFormEnabled: React.Dispatch>; - }) { - if (!isFormEnabled) { - setFormPage(pageToSet); - setIsFormEnabled(true); - } - } - return ( - openFormPage({ - isFormEnabled: isFormEnabled, - setFormPage: formPageFunction, - setIsFormEnabled: isFormEnabledFunction, - }) - } + key="create-button" + onClick={() => setFormPage(<>)} label={buttonLabel} bgColor="bg-indigo-700" icon={ diff --git a/src/components/ContextComponents/Commons/ButtonDelete.tsx b/src/components/ContextComponents/Commons/ButtonDelete.tsx index 8a020e1..4c7b565 100644 --- a/src/components/ContextComponents/Commons/ButtonDelete.tsx +++ b/src/components/ContextComponents/Commons/ButtonDelete.tsx @@ -9,6 +9,7 @@ interface DeleteButtonProps { const DeleteButton: React.FC = ({ onClick }) => { return ( onClick()} label="Seçili Olanları Sil" bgColor="bg-emerald-700" diff --git a/src/components/ContextComponents/Commons/ButtonUpdate.tsx b/src/components/ContextComponents/Commons/ButtonUpdate.tsx index 3b06df4..d8f0463 100644 --- a/src/components/ContextComponents/Commons/ButtonUpdate.tsx +++ b/src/components/ContextComponents/Commons/ButtonUpdate.tsx @@ -4,50 +4,38 @@ import EventButton from "@/components/ContextComponents/Commons/ButtonEvent"; import IsNotAllowed from "./PageisNotAllowed"; interface UpdateButtonProps { - buttonLabel: string; - isFormEnabled: boolean; pageToSet: React.JSX.Element; rowData: any; formPageFunction: React.Dispatch>; - isFormEnabledFunction: React.Dispatch>; } const UpdateButton: React.FC = ({ - buttonLabel, - isFormEnabled, pageToSet, rowData, formPageFunction, - isFormEnabledFunction, }) => { function openFormPage({ - isFormEnabled, setFormPage, - setIsFormEnabled, }: { - isFormEnabled: boolean; setFormPage: React.Dispatch>; - setIsFormEnabled: React.Dispatch>; }) { - if (!isFormEnabled) { - if (JSON.stringify(rowData) === "{}") { - alert("Lütfen bir satır seçiniz."); - formPageFunction(); - isFormEnabledFunction(false); - } else { - setFormPage(pageToSet); - setIsFormEnabled(true); - } + if (JSON.stringify(rowData) === "{}") { + alert("Lütfen bir satır seçiniz."); + formPageFunction(); + // isFormEnabledFunction(false); + } else { + setFormPage(pageToSet); } } + // isFormEnabled: isFormEnabled, + // setIsFormEnabled: isFormEnabledFunction, return ( openFormPage({ - isFormEnabled: isFormEnabled, setFormPage: formPageFunction, - setIsFormEnabled: isFormEnabledFunction, }) } label={buttonLabel} diff --git a/src/components/ContextComponents/Commons/DashPage.tsx b/src/components/ContextComponents/Commons/DashPage.tsx new file mode 100644 index 0000000..33cd360 --- /dev/null +++ b/src/components/ContextComponents/Commons/DashPage.tsx @@ -0,0 +1,21 @@ +"use client"; +import React from "react"; + +interface DashPageProps { + endpointNeeds: any; +} + +const DashPage: React.FC = ({ endpointNeeds }) => { + return ( +
+
+ {endpointNeeds?.create} + {endpointNeeds?.delete} + {endpointNeeds?.assign} +
+ {endpointNeeds?.table} +
+ ); +}; + +export default DashPage; diff --git a/src/components/ContextComponents/Commons/PageCreate.tsx b/src/components/ContextComponents/Commons/PageCreate.tsx index 486efcf..1d2fec1 100644 --- a/src/components/ContextComponents/Commons/PageCreate.tsx +++ b/src/components/ContextComponents/Commons/PageCreate.tsx @@ -1,6 +1,7 @@ +"use client"; import React from "react"; -import IsNotAllowed from "./PageisNotAllowed"; -import EventButton from "./ButtonEvent"; +import EventButton from "@/components/ContextComponents/Commons/ButtonEvent"; + import { Form, FormControl, @@ -13,75 +14,48 @@ import { import { z } from "zod"; import { zodResolver } from "@hookform/resolvers/zod"; import { useForm } from "react-hook-form"; +import { retrieveValidationsByEndpoint } from "../functions/retrieveEndpointAndValidations"; -interface CreatePageButtonProps { - validation: any; - formPageFunction: React.Dispatch>; - isFormEnabledFunction: React.Dispatch>; - onClickAction: () => void; +interface CreatePageProps { + pageInfo: any; + endpoint: string; + returnToPage: any; } -const PageCreate: React.FC = ({ - validation, - formPageFunction, - isFormEnabledFunction, - onClickAction, +const CreatePage: React.FC = ({ + pageInfo, + endpoint, + returnToPage, }) => { const [zodValidation, setZodValidation] = React.useState(z.object({})); - const validationObj: any = validation?.validated; - const validationHeaders = validation?.headers; + const [apiValidation, setApiValidation] = React.useState<{ + [key: string]: any; + }>({}); + const [apiHeaders, setApiHeaders] = React.useState<{ + [key: string]: any; + }>({}); React.useEffect(() => { - console.log("validation", validation); - console.log("validationObj", validationObj); - console.log("validationHeaders", validationHeaders); - - if (Object.keys(validationObj || {}).length === 0) { - let zodValidationInternal: any = {}; - - Object.keys(validationObj).map((key: string) => { - zodValidationInternal[key] = null; - - const keyValidation = validationObj[key] || { - fieldType: { type: "string" }, - required: false, - }; - const fieldType: String = keyValidation.fieldType?.type || "string"; - const required = keyValidation.required || false; - if (fieldType === "string") { - zodValidationInternal[key] = required - ? z.string() - : z.string().optional(); - } else if (fieldType === "integer") { - zodValidationInternal[key] = required - ? z.number() - : z.number().optional(); - } - }); - setZodValidation(zodValidationInternal); - } - }, [validation]); + retrieveValidationsByEndpoint(endpoint).then((validations: any) => { + setZodValidation(validations.zodValidation as any); + setApiHeaders(validations.apiValidation?.headers as Object); + setApiValidation(validations.apiValidation?.validated as Object); + }); + }, []); const form = useForm>({ resolver: zodResolver(zodValidation), }); - function closeFormPage() { - formPageFunction(); - isFormEnabledFunction(false); - } - function onSubmit() { - console.log("onSubmit"); - } + function closeFormPage() {} + function saveAction() {} return ( - <> -

- Bina Oluştur Sayfasına Hoş geldiniz -

+
+

{pageInfo.description}

closeFormPage()} + onClick={() => returnToPage()} label="Dashboarda Dön" bgColor="bg-red-700" icon={ @@ -105,7 +79,7 @@ const PageCreate: React.FC = ({ />
onClickAction()} + onClick={() => saveAction()} label="Kaydet" bgColor="bg-emerald-700" icon={ @@ -129,118 +103,108 @@ const PageCreate: React.FC = ({
{
- - {Object.entries(validationObj).map( - ([key, value]: [string, any]) => { - console.log("key", key); - const keyValidation = validationObj[key] || { - fieldType: { type: "string" }, - required: false, - }; - const fieldType = keyValidation.fieldType?.type || "string"; - if (fieldType === "string" && validationHeaders[key]) { - return ( - <> -
- -
- ( - - - - - - - )} - /> - - - - - - -
-
- - ); - } else if (fieldType === "integer" && validationHeaders[key]) { - return ( - <> -
- -
- ( - - - - - - - )} - /> - - - - - - -
-
- - ); - } + + {Object.keys(apiValidation).map((key: string) => { + const keyValidation = apiValidation[key] || { + fieldType: { type: "string" }, + required: false, + }; + const fieldType = keyValidation.fieldType?.type || "string"; + if (fieldType === "string" && apiValidation[key]) { + return ( +
+ +
+ } + render={({ field }) => ( + + + + + + + )} + /> + + + + + + +
+
+ ); + } else if (fieldType === "integer" && apiValidation[key]) { + return ( +
+ +
+ } + render={({ field }) => ( + + + + + + + )} + /> + + + + + + +
+
+ ); } - )} + })} } - +
); }; -export default PageCreate; +export default CreatePage; diff --git a/src/components/ContextComponents/Commons/PageUpdate.tsx b/src/components/ContextComponents/Commons/PageUpdate.tsx index be225ee..3ad3ab1 100644 --- a/src/components/ContextComponents/Commons/PageUpdate.tsx +++ b/src/components/ContextComponents/Commons/PageUpdate.tsx @@ -13,41 +13,48 @@ import { import { z } from "zod"; import { zodResolver } from "@hookform/resolvers/zod"; import { useForm } from "react-hook-form"; +import { retrieveValidationsByEndpoint } from "../functions/retrieveEndpointAndValidations"; interface UpdatePageButtonProps { - title: string; - validation: any; - tableSelectedRow: any; + endpoint: string; + pageInfo: any; + selectedRow: any; + returnToPage: any; saveFunction: any; - setTableSelectedRow: React.Dispatch>; - formPageFunction: React.Dispatch>; - isFormEnabledFunction: React.Dispatch>; } const PageUpdate: React.FC = ({ - title, - validation, - tableSelectedRow, + endpoint, + pageInfo, + selectedRow, + returnToPage, saveFunction, - setTableSelectedRow, - formPageFunction, - isFormEnabledFunction, }) => { const [validatedData, setValidatedData] = React.useState({}); const [zodValidation, setZodValidation] = React.useState(z.object({})); + const [apiValidation, setApiValidation] = React.useState<{ + [key: string]: any; + }>({}); + const [apiHeaders, setApiHeaders] = React.useState<{ + [key: string]: any; + }>({}); - const validationObj = validation?.validated; - const validationHeaders = validation?.headers; + React.useEffect(() => { + retrieveValidationsByEndpoint(endpoint).then((validations: any) => { + setZodValidation(validations.zodValidation as any); + setApiHeaders(validations.apiValidation?.headers as Object); + setApiValidation(validations.apiValidation?.validated as Object); + }); + }, []); React.useEffect(() => { if (Object.keys(validatedData).length === 0) { - setValidatedData(tableSelectedRow); + setValidatedData(selectedRow); let zodValidationInternal: any = {}; - Object.keys(tableSelectedRow).map((key: string) => { + Object.keys(selectedRow).map((key: string) => { zodValidationInternal[key] = null; - - const keyValidation = validationObj[key] || { + const keyValidation = apiValidation[key] || { fieldType: { type: "string" }, required: false, }; @@ -65,28 +72,21 @@ const PageUpdate: React.FC = ({ }); setZodValidation(zodValidationInternal); } - }, [validation]); + }, []); const form = useForm>({ resolver: zodResolver(zodValidation), }); - function closeFormPage() { - formPageFunction(); - setTableSelectedRow({}); - isFormEnabledFunction(false); - } - function onSubmit(values: z.infer) { - console.log("onSubmit", values); - // saveFunction(validatedData); - } + // function onSubmit(values: z.infer) { + function onSubmit() {} return ( <> -

{title}

+

{pageInfo?.title}

closeFormPage()} + onClick={() => returnToPage()} label="Dashboarda Dön" bgColor="bg-red-700" icon={ @@ -133,122 +133,111 @@ const PageUpdate: React.FC = ({
- {Object.keys(validatedData).length !== 0 && ( -
- - {Object.entries(validatedData).map( - ([key, value]: [string, any]) => { - console.log("key", key); - const keyValidation = validationObj[key] || { - fieldType: { type: "string" }, - required: false, - }; - const fieldType = keyValidation.fieldType?.type || "string"; - if (fieldType === "string" && validationHeaders[key]) { - return ( - <> -
- -
- ( - - - - - - - )} - /> - - - - - - -
-
- - ); - } else if ( - fieldType === "integer" && - validationHeaders[key] - ) { - return ( - <> -
- -
- ( - - - - - - - )} - /> - - - - - - -
-
- - ); - } - } - )} - - - )} +
+ + {Object.keys(apiValidation).map((key: string) => { + const keyValidation = apiValidation[key] || { + fieldType: { type: "string" }, + required: false, + }; + const fieldType = keyValidation.fieldType?.type || "string"; + if (fieldType === "string" && apiValidation[key]) { + return ( +
+ +
+ } + render={({ field }) => ( + + + + + + + )} + /> + + + + + + +
+
+ ); + } else if (fieldType === "integer" && apiValidation[key]) { + return ( +
+ +
+ } + render={({ field }) => ( + + + + + + + )} + /> + + + + + + +
+
+ ); + } + })} + +
); diff --git a/src/components/ContextComponents/Commons/PageisNotAllowed.tsx b/src/components/ContextComponents/Commons/PageisNotAllowed.tsx index 2aa2cbb..058f7a1 100644 --- a/src/components/ContextComponents/Commons/PageisNotAllowed.tsx +++ b/src/components/ContextComponents/Commons/PageisNotAllowed.tsx @@ -1,20 +1,25 @@ import React from "react"; -const IsNotAllowed: React.FC = () => { +interface IsNotAllowedProps { + buttonKey?: string; +} + +const IsNotAllowed: React.FC = ({ buttonKey }) => { return ( - <> -
-
-
-
- - Kullanıcı bu etkinliğe erişim iznine sahip değil. - -
+
+
+
+
+ + Kullanıcı bu etkinliğe erişim iznine sahip değil. +
- +
); }; diff --git a/src/components/ContextComponents/Commons/SearchBar.tsx b/src/components/ContextComponents/Commons/SearchBar.tsx new file mode 100644 index 0000000..48a5498 --- /dev/null +++ b/src/components/ContextComponents/Commons/SearchBar.tsx @@ -0,0 +1,11 @@ +import React from 'react'; + +const SearchBar: React.FC = () => { + return ( +
+ {/* SearchBar component */} +
+ ); +}; + +export default SearchBar; \ No newline at end of file diff --git a/src/components/ContextComponents/Commons/Table.tsx b/src/components/ContextComponents/Commons/Table.tsx index fcc5c8b..bb5dd87 100644 --- a/src/components/ContextComponents/Commons/Table.tsx +++ b/src/components/ContextComponents/Commons/Table.tsx @@ -12,12 +12,16 @@ import { FormLabel, FormMessage, } from "@/components/ui/form"; +import { retrieveHeadersByEndpoint } from "../functions/retrieveEndpointAndValidations"; interface TableProps { - createTable: any; - headers: any; - tableSelectedRow: any; - setTableSelectedRow: React.Dispatch>; + createEndpoint: string; + updateEndpoint: string; + tableFunction: any; + UpdatePage: any; + setFormPage: any; + updatePageInfo: any; + returnToPage: any; } const formSchema = z.object({ @@ -25,227 +29,206 @@ const formSchema = z.object({ }); const Table: React.FC = ({ - createTable, - tableSelectedRow, - setTableSelectedRow, - headers, + createEndpoint, + updateEndpoint, + tableFunction, + UpdatePage, + setFormPage, + updatePageInfo, + returnToPage, }) => { - const [initalData, setInitalData] = React.useState([]); + const [apiHeaders, setApiHeaders] = React.useState([]); const [tabledata, settabledata] = React.useState([]); - const [headersList, setHeadersList] = React.useState([]); - - const incomingHeaders = Array.from(Object.values(headers)) || []; - const headersObject = headers || {}; + const [searchDropDown, setSearchDropDown] = React.useState(""); const form = useForm>({ resolver: zodResolver(formSchema), }); - React.useEffect(() => { - if (incomingHeaders.length !== 0) { - let headersNew: any = []; - createTable({}) - .then((res: any) => { - const resData: any = res?.data || []; - if (resData?.length > 0) { - settabledata(resData || []); - setInitalData(resData || []); - for (const key in resData[0]) { - if (Object.keys(headersObject).includes(key)) { - headersNew.push(headers[key]); - } else { - console.log("key", key); - } - } - if (headersNew.length > 0) { - setHeadersList(headersNew); - } - } - }) - .catch((err: any) => {}); - } - }, [headers]); - - function cleanSearch() { - form.setValue("searchText", ""); - settabledata(Array.from(initalData)); + function retrieveData(query: null | any = null) { + return tableFunction(query) + .then((res: any) => { + settabledata(res?.data || []); + return res?.data || []; + }) + .catch((err: any) => {}); } - function search(values: z.infer) { - const searchText = values.searchText; + React.useEffect(() => { + retrieveHeadersByEndpoint(createEndpoint).then((validations: any) => { + if (validations?.headers.length !== 0) { + tableFunction({ + page: 1, + limit: 10, + order_field: "uu_id", + order_type: "desc", + }) + .then((response: any) => { + settabledata(response?.data || []); + for (const key in response?.data[0]) { + if (Object.keys(validations?.headers).includes(key)) { + setApiHeaders((prev: string[]) => [ + ...prev, + validations?.headers[key], + ]); + } + } + }) + .catch((err: any) => {}); + } + retrieveData(); + }); + }, []); + + function cleanSearch() { + retrieveData(); + } + + function searchByForm() { + const searchText = form.getValues("searchText"); if (searchText === "") { - settabledata(Array.from(initalData)); + cleanSearch(); } else { - const filteredList = Array.from(tabledata).filter((item) => { - return Object.values(item).some((row: any) => { - console.log(row); - return row.toLowerCase().includes(searchText.toLowerCase()); - }); - }); - console.log("filteredList", filteredList); - settabledata(filteredList); + if (searchText.length > 3) { + setQuery({ searchDropDown: searchText }); + retrieveData(); + } } } + function updateSelectedRow({ selectedComponent }: any) { + setFormPage( + console.log("saveFunction")} + /> + ); + } + return ( <> -
-
-
-
setTableSelectedRow({})} - > - - +
+
+ +
+ ( + + + + + + + )} + /> + + +
+ + +
+
+ {tabledata.map((row: any) => { + return ( + + updateSelectedRow({ selectedComponent: row })} + xmlns="http://www.w3.org/2000/svg" + width="28" + height="28" + viewBox="0 0 24 24" + fill="none" + stroke="currentColor" + strokeWidth="2" + strokeLinecap="round" + strokeLinejoin="round" + className="lucide lucide-pencil" + > + + - Seçimleri Temizle -
-
-
-
- -
- ( - - - - - - - )} - /> - - -
- - -
-
-
- -
-
+ ); + })}
- {headersList.map((header, key) => ( - - ))} + {apiHeaders && + apiHeaders?.map((header, key) => ( + + ))} + - {tabledata.map((packageItem: any) => ( - - setTableSelectedRow( - tableSelectedRow.uu_id == packageItem.uu_id - ? {} - : packageItem - ) - } - > - {Object.entries(packageItem).map( + {tabledata.map((row: any) => ( + + {Object.entries(row).map( ([key, value]: [key: string, value: any]) => { return ( ); } diff --git a/src/components/ContextComponents/Commons/isNotAllowedButton.tsx b/src/components/ContextComponents/Commons/isNotAllowedButton.tsx index e7af1bf..c4a725d 100644 --- a/src/components/ContextComponents/Commons/isNotAllowedButton.tsx +++ b/src/components/ContextComponents/Commons/isNotAllowedButton.tsx @@ -3,13 +3,18 @@ import React from "react"; import EventButton from "@/components/ContextComponents/Commons/ButtonEvent"; interface IsNotAllowedButtonProps { + buttonKey: string; label: string; } -const IsNotAllowedButton: React.FC = ({ label }) => { +const IsNotAllowedButton: React.FC = ({ + label, + buttonKey, +}) => { return ( <> { + if (JSON.stringify(validator?.validated) !== "{}") { + apiValidation = validator; + Object.keys(validator?.validated).map((key: string) => { + zodValidation[key] = null; + const keyValidation = validator?.validated[key] || { + fieldType: { type: "string" }, + required: false, + }; + const fieldType: String = keyValidation.fieldType?.type || "string"; + const required = keyValidation.required || false; + if (fieldType === "string") { + zodValidation[key] = required ? z.string() : z.string().optional(); + } else if (fieldType === "integer") { + zodValidation[key] = required ? z.number() : z.number().optional(); + } + }); + return { + zodValidation: zodValidation, + apiValidation: apiValidation, + }; + } + }) + .catch(() => {}); + return { + zodValidation: zodValidation, + apiValidation: apiValidation, + }; +} + +async function retrieveHeadersByEndpoint(endpoint: string) { + let headers: any = {}; + + await retrieveHeadersEndpoint({ + endpoint: endpoint, + }) + .then((validator) => { + if (JSON.stringify(validator?.headers) !== "{}") { + headers = validator?.headers; + return { + headers: headers, + }; + } + }) + .catch(() => {}); + return { + headers: headers, + }; +} + +export { retrieveValidationsByEndpoint, retrieveHeadersByEndpoint }; diff --git a/src/components/Dashboards/DashboardPage.tsx b/src/components/Dashboards/DashboardPage.tsx index dde1914..96b3e46 100644 --- a/src/components/Dashboards/DashboardPage.tsx +++ b/src/components/Dashboards/DashboardPage.tsx @@ -13,8 +13,12 @@ const DashboardPage: React.FC = ({ }) => { const [activePage, setActivePage] = React.useState(); const [activeMenu, setActiveMenu] = React.useState(leftSideMenuContent); + const [activeValidationList, setActiveValidationList] = React.useState([]); + const [activeValidation, setActiveValidation] = React.useState({}); - React.useEffect(() => {}, [activeMenu]); + React.useEffect(( + + ) => {}, [activeMenu]); return (
- {header} - + {header} +
-
- {value || ""} -
+
{value || ""}