create page updated
This commit is contained in:
parent
66bbb58ef3
commit
9c42225080
|
|
@ -14,6 +14,7 @@ import {
|
||||||
retrieveHeadersEndpoint,
|
retrieveHeadersEndpoint,
|
||||||
retrieveHeadersAndValidationByEndpoint,
|
retrieveHeadersAndValidationByEndpoint,
|
||||||
} from "@/(apicalls)/validations/validations";
|
} from "@/(apicalls)/validations/validations";
|
||||||
|
import PageCreate from "../../Commons/PageCreate";
|
||||||
|
|
||||||
const Build: React.FC = () => {
|
const Build: React.FC = () => {
|
||||||
const [renderTable, setRenderTable] = React.useState(false);
|
const [renderTable, setRenderTable] = React.useState(false);
|
||||||
|
|
@ -47,8 +48,9 @@ const Build: React.FC = () => {
|
||||||
isRender: setRenderTable,
|
isRender: setRenderTable,
|
||||||
},
|
},
|
||||||
update: {
|
update: {
|
||||||
endpoint: "/building/build/create",
|
endpoint: "/building/build/update",
|
||||||
variableReact: setCreateValidation,
|
isRender: setRenderUpdate,
|
||||||
|
variableReact: setUpdateValidation,
|
||||||
variableKey: "validation",
|
variableKey: "validation",
|
||||||
component: renderUpdate ? (
|
component: renderUpdate ? (
|
||||||
<UpdateButton
|
<UpdateButton
|
||||||
|
|
@ -57,7 +59,7 @@ const Build: React.FC = () => {
|
||||||
isFormEnabled={isFormEnabled}
|
isFormEnabled={isFormEnabled}
|
||||||
pageToSet={
|
pageToSet={
|
||||||
<BuildUpdatePage
|
<BuildUpdatePage
|
||||||
validation={createValidation}
|
validation={updateValidation}
|
||||||
tableSelectedRow={tableSelectedRow}
|
tableSelectedRow={tableSelectedRow}
|
||||||
setTableSelectedRow={setTableSelectedRow}
|
setTableSelectedRow={setTableSelectedRow}
|
||||||
formPageFunction={setFormPage}
|
formPageFunction={setFormPage}
|
||||||
|
|
@ -68,27 +70,32 @@ const Build: React.FC = () => {
|
||||||
isFormEnabledFunction={setIsFormEnabled}
|
isFormEnabledFunction={setIsFormEnabled}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<IsNotAllowedButton label="Bina Oluştur" />
|
<IsNotAllowedButton label="Bina Güncelle" />
|
||||||
),
|
),
|
||||||
isRender: setRenderCreate,
|
|
||||||
},
|
},
|
||||||
create: {
|
create: {
|
||||||
endpoint: "/building/build/update/{build_uu_id}",
|
endpoint: "/building/build/create",
|
||||||
variableReact: setUpdateValidation,
|
isRender: setRenderCreate,
|
||||||
variableKey: "headers",
|
variableReact: setCreateValidation,
|
||||||
|
variableKey: "validation",
|
||||||
component: renderCreate ? (
|
component: renderCreate ? (
|
||||||
<CreateButton
|
<CreateButton
|
||||||
validation={updateValidation}
|
|
||||||
title="Bina Oluştur Sayfasına Hoş geldiniz"
|
|
||||||
buttonLabel="Yeni Bina ekle"
|
buttonLabel="Yeni Bina ekle"
|
||||||
|
pageToSet={
|
||||||
|
<PageCreate
|
||||||
|
validation={createValidation}
|
||||||
|
formPageFunction={setFormPage}
|
||||||
|
isFormEnabledFunction={setIsFormEnabled}
|
||||||
|
onClickAction={() => console.log("Create button clicked")}
|
||||||
|
/>
|
||||||
|
}
|
||||||
isFormEnabled={isFormEnabled}
|
isFormEnabled={isFormEnabled}
|
||||||
formPageFunction={setFormPage}
|
formPageFunction={setFormPage}
|
||||||
isFormEnabledFunction={setIsFormEnabled}
|
isFormEnabledFunction={setIsFormEnabled}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<IsNotAllowedButton label="Binayı Güncelle" />
|
<IsNotAllowedButton label="Binayı Oluştur" />
|
||||||
),
|
),
|
||||||
isRender: setRenderUpdate,
|
|
||||||
},
|
},
|
||||||
delete: {
|
delete: {
|
||||||
endpoint: "/building/build/delete",
|
endpoint: "/building/build/delete",
|
||||||
|
|
@ -115,26 +122,23 @@ const Build: React.FC = () => {
|
||||||
setTableHeaders(validator?.headers);
|
setTableHeaders(validator?.headers);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {});
|
.catch(() => {});
|
||||||
} else if (endpointNeed.variableKey === "validation") {
|
} else if (endpointNeed.variableKey === "validation") {
|
||||||
retrieveHeadersAndValidationByEndpoint({
|
retrieveHeadersAndValidationByEndpoint({
|
||||||
endpoint: endpointNeed.endpoint,
|
endpoint: endpointNeed.endpoint,
|
||||||
})
|
})
|
||||||
.then((validator) => {
|
.then((validator) => {
|
||||||
console.log("validator", validator);
|
|
||||||
if (JSON.stringify(validator?.validated) !== "{}") {
|
if (JSON.stringify(validator?.validated) !== "{}") {
|
||||||
endpointNeed.variableReact(validator);
|
endpointNeed.variableReact(validator);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {});
|
.catch(() => {});
|
||||||
}
|
}
|
||||||
endpointNeed.isRender(true);
|
endpointNeed.isRender(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch(() => {});
|
||||||
console.log("error", error);
|
|
||||||
});
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
|
|
@ -1,34 +1,24 @@
|
||||||
"use client";
|
"use client";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import EventButton from "@/components/ContextComponents/Commons/ButtonEvent";
|
import EventButton from "@/components/ContextComponents/Commons/ButtonEvent";
|
||||||
import PageCreate from "@/components/ContextComponents/Commons/PageCreate";
|
|
||||||
|
|
||||||
interface CreateButtonProps {
|
interface CreateButtonProps {
|
||||||
title: string;
|
|
||||||
validation: any;
|
|
||||||
buttonLabel: string;
|
buttonLabel: string;
|
||||||
|
pageToSet: any;
|
||||||
isFormEnabled: boolean;
|
isFormEnabled: boolean;
|
||||||
formPageFunction: React.Dispatch<React.SetStateAction<React.JSX.Element>>;
|
formPageFunction: React.Dispatch<React.SetStateAction<React.JSX.Element>>;
|
||||||
isFormEnabledFunction: React.Dispatch<React.SetStateAction<boolean>>;
|
isFormEnabledFunction: React.Dispatch<React.SetStateAction<boolean>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CreateButton: React.FC<CreateButtonProps> = ({
|
const CreateButton: React.FC<CreateButtonProps> = ({
|
||||||
title,
|
|
||||||
validation,
|
pageToSet,
|
||||||
buttonLabel,
|
buttonLabel,
|
||||||
isFormEnabled,
|
isFormEnabled,
|
||||||
formPageFunction,
|
formPageFunction,
|
||||||
isFormEnabledFunction,
|
isFormEnabledFunction,
|
||||||
}) => {
|
}) => {
|
||||||
const pageCreate = (
|
|
||||||
<PageCreate
|
|
||||||
validation={validation}
|
|
||||||
title={title}
|
|
||||||
formPageFunction={formPageFunction}
|
|
||||||
isFormEnabledFunction={isFormEnabledFunction}
|
|
||||||
onClickAction={() => console.log("Create button clicked")}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
|
|
||||||
function openFormPage({
|
function openFormPage({
|
||||||
isFormEnabled,
|
isFormEnabled,
|
||||||
|
|
@ -40,7 +30,7 @@ const CreateButton: React.FC<CreateButtonProps> = ({
|
||||||
setIsFormEnabled: React.Dispatch<React.SetStateAction<boolean>>;
|
setIsFormEnabled: React.Dispatch<React.SetStateAction<boolean>>;
|
||||||
}) {
|
}) {
|
||||||
if (!isFormEnabled) {
|
if (!isFormEnabled) {
|
||||||
setFormPage(pageCreate);
|
setFormPage(pageToSet);
|
||||||
setIsFormEnabled(true);
|
setIsFormEnabled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,20 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import IsNotAllowed from "./PageisNotAllowed";
|
import IsNotAllowed from "./PageisNotAllowed";
|
||||||
import EventButton from "./ButtonEvent";
|
import EventButton from "./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";
|
||||||
|
|
||||||
interface CreatePageButtonProps {
|
interface CreatePageButtonProps {
|
||||||
title: string;
|
|
||||||
validation: any;
|
validation: any;
|
||||||
formPageFunction: React.Dispatch<React.SetStateAction<React.JSX.Element>>;
|
formPageFunction: React.Dispatch<React.SetStateAction<React.JSX.Element>>;
|
||||||
isFormEnabledFunction: React.Dispatch<React.SetStateAction<boolean>>;
|
isFormEnabledFunction: React.Dispatch<React.SetStateAction<boolean>>;
|
||||||
|
|
@ -11,20 +22,63 @@ interface CreatePageButtonProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
const PageCreate: React.FC<CreatePageButtonProps> = ({
|
const PageCreate: React.FC<CreatePageButtonProps> = ({
|
||||||
title,
|
|
||||||
validation,
|
validation,
|
||||||
formPageFunction,
|
formPageFunction,
|
||||||
isFormEnabledFunction,
|
isFormEnabledFunction,
|
||||||
onClickAction,
|
onClickAction,
|
||||||
}) => {
|
}) => {
|
||||||
|
const [zodValidation, setZodValidation] = React.useState(z.object({}));
|
||||||
|
const validationObj: any = validation?.validated;
|
||||||
|
const validationHeaders = validation?.headers;
|
||||||
|
|
||||||
|
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]);
|
||||||
|
|
||||||
|
const form = useForm<z.infer<typeof zodValidation>>({
|
||||||
|
resolver: zodResolver(zodValidation),
|
||||||
|
});
|
||||||
|
|
||||||
function closeFormPage() {
|
function closeFormPage() {
|
||||||
formPageFunction(<IsNotAllowed />);
|
formPageFunction(<IsNotAllowed />);
|
||||||
isFormEnabledFunction(false);
|
isFormEnabledFunction(false);
|
||||||
}
|
}
|
||||||
|
function onSubmit() {
|
||||||
|
console.log("onSubmit");
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<h1 className="text-center text-3xl">{title}</h1>
|
<h1 className="text-center text-3xl">
|
||||||
|
Bina Oluştur Sayfasına Hoş geldiniz
|
||||||
|
</h1>
|
||||||
<div className=" md:flex items-center py-5 my-5 rounded-sm border border-stroke bg-white shadow-default dark:border-strokedark dark:bg-boxdark">
|
<div className=" md:flex items-center py-5 my-5 rounded-sm border border-stroke bg-white shadow-default dark:border-strokedark dark:bg-boxdark">
|
||||||
<EventButton
|
<EventButton
|
||||||
onClick={() => closeFormPage()}
|
onClick={() => closeFormPage()}
|
||||||
|
|
@ -73,6 +127,118 @@ const PageCreate: React.FC<CreatePageButtonProps> = ({
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{
|
||||||
|
<Form {...form}>
|
||||||
|
<form
|
||||||
|
// onSubmit={onSubmit}
|
||||||
|
className="space-y-5 max-w-3xl mx-auto py-10"
|
||||||
|
>
|
||||||
|
{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 (
|
||||||
|
<>
|
||||||
|
<div className="mb-4">
|
||||||
|
<label className="mb-2.5 block font-medium text-black dark:text-white">
|
||||||
|
{validationHeaders[key] || "Unknown"}
|
||||||
|
</label>
|
||||||
|
<div className="relative">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name={key}
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormControl>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
className="w-full rounded-lg border border-stroke bg-transparent py-4 pl-6 pr-10 text-black outline-none focus:border-primary focus-visible:shadow-none dark:border-form-strokedark dark:bg-form-input dark:text-white dark:focus:border-primary"
|
||||||
|
{...field}
|
||||||
|
value={field.value}
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<span className="absolute right-4 top-4">
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
width="24"
|
||||||
|
height="24"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
strokeWidth="2"
|
||||||
|
strokeLinecap="round"
|
||||||
|
strokeLinejoin="round"
|
||||||
|
className="lucide lucide-pencil"
|
||||||
|
>
|
||||||
|
<path d="M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z" />
|
||||||
|
<path d="m15 5 4 4" />
|
||||||
|
</svg>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
} else if (fieldType === "integer" && validationHeaders[key]) {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className="mb-4">
|
||||||
|
<label className="mb-2.5 block font-medium text-black dark:text-white">
|
||||||
|
{validationHeaders[key] || "Unknown"}
|
||||||
|
</label>
|
||||||
|
<div className="relative">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name={key}
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormControl>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
className="w-full rounded-lg border border-stroke bg-transparent py-4 pl-6 pr-10 text-black outline-none focus:border-primary focus-visible:shadow-none dark:border-form-strokedark dark:bg-form-input dark:text-white dark:focus:border-primary"
|
||||||
|
{...field}
|
||||||
|
value={field.value}
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<span className="absolute right-4 top-4">
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
width="24"
|
||||||
|
height="24"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
strokeWidth="2"
|
||||||
|
strokeLinecap="round"
|
||||||
|
strokeLinejoin="round"
|
||||||
|
className="lucide lucide-pencil"
|
||||||
|
>
|
||||||
|
<path d="M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z" />
|
||||||
|
<path d="m15 5 4 4" />
|
||||||
|
</svg>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)}
|
||||||
|
</form>
|
||||||
|
</Form>
|
||||||
|
}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ const PageUpdate: React.FC<UpdatePageButtonProps> = ({
|
||||||
setValidatedData(tableSelectedRow);
|
setValidatedData(tableSelectedRow);
|
||||||
let zodValidationInternal: any = {};
|
let zodValidationInternal: any = {};
|
||||||
|
|
||||||
Object.entries(tableSelectedRow).map(([key, value]: [string, any]) => {
|
Object.keys(tableSelectedRow).map((key: string) => {
|
||||||
zodValidationInternal[key] = null;
|
zodValidationInternal[key] = null;
|
||||||
|
|
||||||
const keyValidation = validationObj[key] || {
|
const keyValidation = validationObj[key] || {
|
||||||
|
|
@ -54,7 +54,6 @@ const PageUpdate: React.FC<UpdatePageButtonProps> = ({
|
||||||
const fieldType: String = keyValidation.fieldType?.type || "string";
|
const fieldType: String = keyValidation.fieldType?.type || "string";
|
||||||
const required = keyValidation.required || false;
|
const required = keyValidation.required || false;
|
||||||
if (fieldType === "string") {
|
if (fieldType === "string") {
|
||||||
console.log("key", key, "value", value);
|
|
||||||
zodValidationInternal[key] = required
|
zodValidationInternal[key] = required
|
||||||
? z.string()
|
? z.string()
|
||||||
: z.string().optional();
|
: z.string().optional();
|
||||||
|
|
@ -147,7 +146,6 @@ const PageUpdate: React.FC<UpdatePageButtonProps> = ({
|
||||||
required: false,
|
required: false,
|
||||||
};
|
};
|
||||||
const fieldType = keyValidation.fieldType?.type || "string";
|
const fieldType = keyValidation.fieldType?.type || "string";
|
||||||
const required = keyValidation.required || false;
|
|
||||||
if (fieldType === "string" && validationHeaders[key]) {
|
if (fieldType === "string" && validationHeaders[key]) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue