pages updated
This commit is contained in:
96
oldCode/building/create/CreatePage.tsx
Normal file
96
oldCode/building/create/CreatePage.tsx
Normal file
@@ -0,0 +1,96 @@
|
||||
"use client";
|
||||
import { RetrieveInputByType } from "@/hooks/renderInputWithValidation";
|
||||
import * as z from "zod";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { useForm } from "react-hook-form";
|
||||
|
||||
import {
|
||||
Form,
|
||||
FormControl,
|
||||
FormField,
|
||||
FormItem,
|
||||
FormLabel,
|
||||
FormMessage,
|
||||
FormDescription,
|
||||
} from "@/components/ui/form";
|
||||
import { convertApiValidationToZodValidation } from "@/lib/renderZodValidation";
|
||||
|
||||
interface CreatePageComponentInterface {
|
||||
validator: any;
|
||||
headers: any;
|
||||
}
|
||||
|
||||
const CreatePageComponent: React.FC<CreatePageComponentInterface> = ({
|
||||
validator,
|
||||
headers,
|
||||
}) => {
|
||||
const returnValidation = convertApiValidationToZodValidation(validator);
|
||||
const { validSchemaZod, zodValidation, apiValidation } = returnValidation;
|
||||
|
||||
const form = useForm<z.infer<typeof validSchemaZod>>({
|
||||
resolver: zodResolver(validSchemaZod),
|
||||
defaultValues: {},
|
||||
});
|
||||
|
||||
function submitUpdate(formData: z.infer<typeof validSchemaZod>) {
|
||||
// saveFunction({
|
||||
// uu_id: updateUUID,
|
||||
// payload: validDataParser(formData),
|
||||
// }).then((res: any) => {
|
||||
// console.log(res);
|
||||
// if (res?.status === 200) {
|
||||
// } else {
|
||||
// alert("Güncelleme başarısız");
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="container mx-auto p-4">
|
||||
<Form {...form}>
|
||||
<form action="">
|
||||
{Object.entries(validator).map(([key, value]: [string, any]) => (
|
||||
<FormField
|
||||
key={key}
|
||||
control={form.control}
|
||||
name={String(key)}
|
||||
render={({ field }) => {
|
||||
return (
|
||||
<FormItem>
|
||||
<FormLabel>
|
||||
{headers[key] || `Header not found ${key}`}
|
||||
</FormLabel>
|
||||
<FormControl>
|
||||
{RetrieveInputByType({
|
||||
type: value?.fieldType || "string",
|
||||
props: {
|
||||
className: "",
|
||||
field: field,
|
||||
placeholder: headers[key],
|
||||
required: value?.required || false,
|
||||
},
|
||||
})}
|
||||
</FormControl>
|
||||
{String(form.formState.errors[key]?.type) ===
|
||||
"invalid_type" ? (
|
||||
<span id={key} className="text-red-700">
|
||||
"Lütfen metinsel bir değer giriniz"
|
||||
</span>
|
||||
) : (
|
||||
<></>
|
||||
)}
|
||||
</FormItem>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
<button type="submit" className="mt-4">
|
||||
Submit
|
||||
</button>
|
||||
</form>
|
||||
</Form>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default CreatePageComponent;
|
||||
40
oldCode/building/create/page.tsx
Normal file
40
oldCode/building/create/page.tsx
Normal file
@@ -0,0 +1,40 @@
|
||||
"use server";
|
||||
|
||||
import { retrieveAvailableEndpoint } from "@/apicalls/checkEndpoint";
|
||||
import { checkAccessTokenIsValid } from "@/apicalls/cookies/token";
|
||||
import { decryptQuery, defaultPagination } from "@/apicalls/test";
|
||||
import { retrieveHeadersAndValidationByEndpoint } from "@/apicalls/validations/validations";
|
||||
import { redirect } from "next/navigation";
|
||||
import CreatePageComponent from "./CreatePage";
|
||||
|
||||
export default async function BuildingCreatePage({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: any;
|
||||
}) {
|
||||
if (!(await checkAccessTokenIsValid())) {
|
||||
redirect("/login/email");
|
||||
}
|
||||
|
||||
const buildKey = "building";
|
||||
const searchParamsKeys = await searchParams;
|
||||
const endpointUrl = "/building/build/create";
|
||||
|
||||
const queryEncrypt = await decryptQuery(searchParamsKeys?.q);
|
||||
const endpointAvailable = await retrieveAvailableEndpoint(endpointUrl);
|
||||
const validateAndHeaders = await retrieveHeadersAndValidationByEndpoint({
|
||||
endpoint: endpointUrl,
|
||||
});
|
||||
const validator = validateAndHeaders?.validated || {};
|
||||
const headers = validateAndHeaders?.headers || {};
|
||||
console.log("validateAndHeaders", validateAndHeaders);
|
||||
console.log("endpointAvailable", endpointAvailable);
|
||||
console.log("queryEncrypt", queryEncrypt);
|
||||
return (
|
||||
<div>
|
||||
<h1>Create Building</h1>
|
||||
<h1>{JSON.stringify(queryEncrypt)}</h1>
|
||||
<CreatePageComponent validator={validator} headers={headers} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user