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>
|
||||
);
|
||||
}
|
||||
159
oldCode/building/page.tsx
Normal file
159
oldCode/building/page.tsx
Normal file
@@ -0,0 +1,159 @@
|
||||
"use server";
|
||||
import React from "react";
|
||||
import Link from "next/link";
|
||||
import { redirect } from "next/navigation";
|
||||
import { RefreshCcw, PlusCircle } from "lucide-react";
|
||||
import {
|
||||
decryptQuery,
|
||||
defaultPagination,
|
||||
handleFormSubmission,
|
||||
} from "@/apicalls/test";
|
||||
import { TableComponent } from "@/components/commons/Table";
|
||||
import Pagination from "@/components/commons/pagination";
|
||||
import MainBodyWithHeader from "@/components/defaultLayout/MainBodyWithHeader";
|
||||
import {
|
||||
createBuild,
|
||||
retrieveBuildList,
|
||||
updateBuild,
|
||||
} from "@/apicalls/building/build";
|
||||
import {
|
||||
checkAccessTokenIsValid,
|
||||
retrieveUserSelection,
|
||||
} from "@/apicalls/cookies/token";
|
||||
import { retrievePageInfoByComponentName } from "@/hooks/retrievePageInfoByComponentName";
|
||||
import { checkPageAvaliable } from "@/hooks/checkpageAvaliable";
|
||||
|
||||
const BuildinPage = async ({ searchParams }: { searchParams: any }) => {
|
||||
const buildKey = "building";
|
||||
const pageName = "BuildingPage";
|
||||
const searchParamsKeys = await searchParams;
|
||||
|
||||
if (!searchParamsKeys?.q) {
|
||||
const defaultURL = await defaultPagination();
|
||||
redirect(`/${buildKey}?q=${defaultURL}`);
|
||||
}
|
||||
const queryEncrypt = await decryptQuery(searchParamsKeys?.q);
|
||||
if (!(await checkAccessTokenIsValid())) {
|
||||
redirect("/login/email");
|
||||
}
|
||||
const user = await retrieveUserSelection();
|
||||
|
||||
const tableValues = {
|
||||
endpoint: "building/build/list",
|
||||
name: "table",
|
||||
url: "/building",
|
||||
function: retrieveBuildList,
|
||||
data: [],
|
||||
headers: {},
|
||||
validation: {},
|
||||
};
|
||||
const createValues = {
|
||||
endpoint: "building/build/create",
|
||||
name: "create",
|
||||
url: "/building/create",
|
||||
function: createBuild,
|
||||
data: [],
|
||||
headers: {},
|
||||
validation: {},
|
||||
};
|
||||
const updateValues = {
|
||||
endpoint: "building/build/update/{build_uu_id}",
|
||||
function: updateBuild,
|
||||
name: "update",
|
||||
url: "/building/update",
|
||||
data: [],
|
||||
headers: {},
|
||||
validation: {},
|
||||
};
|
||||
|
||||
let restrictions: any = {
|
||||
update: updateValues,
|
||||
create: createValues,
|
||||
table: tableValues,
|
||||
};
|
||||
|
||||
if (!user?.lang) {
|
||||
return (
|
||||
<MainBodyWithHeader
|
||||
children={<h1>User selection is not successfully retrieved.</h1>}
|
||||
/>
|
||||
);
|
||||
} else {
|
||||
const pageContent = retrievePageInfoByComponentName(pageName, user?.lang);
|
||||
const restrictionsChecked = await checkPageAvaliable({
|
||||
pageContent,
|
||||
restrictions,
|
||||
queryEncrypt,
|
||||
});
|
||||
|
||||
if (!restrictionsChecked || !restrictionsChecked?.table) {
|
||||
return (
|
||||
<MainBodyWithHeader
|
||||
children={<h1>This user does not have access to this page.</h1>}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
const BuildingPage = (
|
||||
<div className="p-4 overflow-hidden">
|
||||
<h1 className="text-2xl font-bold mb-4 ">Dashboard</h1>
|
||||
<form
|
||||
action={handleFormSubmission}
|
||||
className="bg-white p-4 rounded-lg shadow"
|
||||
>
|
||||
<div className="grid gap-4">
|
||||
<p>Welcome to your dashboard</p>
|
||||
{restrictionsChecked?.create && (
|
||||
<Link
|
||||
href={"/building/create"}
|
||||
className="flex items-center justify-center gap-2 px-4 py-2 bg-slate-500 text-white rounded hover:bg-slate-700"
|
||||
>
|
||||
<PlusCircle size={16} />
|
||||
Create
|
||||
</Link>
|
||||
)}
|
||||
<h1>{JSON.stringify(queryEncrypt)}</h1>
|
||||
|
||||
{restrictionsChecked && (
|
||||
<div>
|
||||
<input type="hidden" name="section" value={buildKey} readOnly />
|
||||
<TableComponent
|
||||
pageContent={pageContent}
|
||||
tableValidateAndHeaders={restrictionsChecked?.table}
|
||||
apiFunction={retrieveBuildList}
|
||||
redirectTo={"/building/update"}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
className="flex items-center justify-center gap-2 px-4 py-2 bg-slate-500 text-white rounded hover:bg-slate-700"
|
||||
>
|
||||
<RefreshCcw size={16} />
|
||||
Search
|
||||
</button>
|
||||
<Pagination
|
||||
size={parseInt(queryEncrypt?.size || "10")}
|
||||
page={parseInt(queryEncrypt?.page || "1")}
|
||||
orderBy={queryEncrypt?.orderBy || "id"}
|
||||
orderType={queryEncrypt?.orderType || "asc"}
|
||||
totalPage={3}
|
||||
/>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
return (
|
||||
<>
|
||||
<MainBodyWithHeader
|
||||
children={BuildingPage}
|
||||
section={`/${buildKey}`}
|
||||
profileInfo={user}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export default BuildinPage;
|
||||
55
oldCode/building/update/page.tsx
Normal file
55
oldCode/building/update/page.tsx
Normal file
@@ -0,0 +1,55 @@
|
||||
"use server";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
import { updateBuild } from "@/apicalls/building/build";
|
||||
import { retrieveAvailableEndpoint } from "@/apicalls/checkEndpoint";
|
||||
import { checkAccessTokenIsValid } from "@/apicalls/cookies/token";
|
||||
import { decryptQuery, defaultPagination } from "@/apicalls/test";
|
||||
import { retrieveHeadersAndValidationByEndpoint } from "@/apicalls/validations/validations";
|
||||
|
||||
import { RetrieveInputByType } from "@/hooks/renderInputWithValidation";
|
||||
|
||||
import React from "react";
|
||||
import UpdatePageComponent from "@/components/commons/UpdatePage";
|
||||
|
||||
export default async function BuildingUpdatePage({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: any;
|
||||
}) {
|
||||
if (!(await checkAccessTokenIsValid())) {
|
||||
redirect("/login/email");
|
||||
}
|
||||
|
||||
const buildKey = "building/update";
|
||||
const searchParamsKeys = await searchParams;
|
||||
const endpointUrl = "building/build/update/{build_uu_id}";
|
||||
if (!searchParamsKeys?.q) {
|
||||
redirect(`/${buildKey}`);
|
||||
}
|
||||
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("endpointAvailable", endpointAvailable);
|
||||
console.log("validator", validator);
|
||||
console.log("headers", headers);
|
||||
console.log("queryEncrypt", queryEncrypt);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1>Update Building</h1>
|
||||
<h1>{JSON.stringify(queryEncrypt)}</h1>
|
||||
|
||||
<UpdatePageComponent
|
||||
validator={validator}
|
||||
headers={headers}
|
||||
queryEncrypt={queryEncrypt}
|
||||
commitFunction={updateBuild}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user