78 lines
3.6 KiB
TypeScript
78 lines
3.6 KiB
TypeScript
'use client';
|
|
import React, { useState } from "react";
|
|
import Link from "next/link";
|
|
import { EyeIcon, PencilIcon, PlusCircle, ArrowLeftFromLineIcon, ExpandIcon } from "lucide-react";
|
|
|
|
import { ContentProps } from "@/validations/mutual/dashboard/props";
|
|
import { getSchemaByLanguage } from "@/schemas/custom/building/parts/tenantSomething/schemas";
|
|
|
|
import TableComponent from "@/components/mutual/tableView/FullTableComp/component";
|
|
import CreateForm from "@/components/mutual/tableView/mutual/CreateForm";
|
|
import UpdateForm from "@/components/mutual/tableView/mutual/UpdateForm";
|
|
import ViewForm from "@/components/mutual/tableView/mutual/ViewForm";
|
|
import { API_BASE_URL } from "@/config/config";
|
|
|
|
// This is a mock page dont use it
|
|
const aPage: React.FC<ContentProps> = ({ lang, translations, activePageUrl, mode }) => {
|
|
const [selectedRow, setSelectedRow] = useState<any>(null);
|
|
|
|
const getSchema = getSchemaByLanguage(lang)
|
|
const isList = mode === 'shortList' || mode === 'fullList'
|
|
const basePageUrl = `/${lang}/${activePageUrl}?mode=`
|
|
const pageUrl = `${basePageUrl}shortList`
|
|
const urls = { list: `${API_BASE_URL}/tst` }
|
|
const initPaginationDefault = { page: 1, size: 10, orderFields: [], orderTypes: [], query: {} }
|
|
const renderLastRowComponent = (reDirectUrl: string, IconToWrap: any, key: string) => {
|
|
return <Link key={key} className="flex items-center gap-2" replace href={reDirectUrl} ><IconToWrap /></Link>
|
|
}
|
|
const RenderBackToList = <div onClick={() => setSelectedRow(null)}>{renderLastRowComponent(pageUrl, ArrowLeftFromLineIcon, "backToList")}</div>
|
|
const redirectUrls = {
|
|
table: {
|
|
update: renderLastRowComponent(`${basePageUrl}update`, PencilIcon, "update"),
|
|
view: renderLastRowComponent(`${basePageUrl}view`, EyeIcon, "view"),
|
|
},
|
|
page: {
|
|
create: renderLastRowComponent(`${basePageUrl}create`, PlusCircle, "create"),
|
|
size: <Link key="size-table" href={mode === 'shortList' ? `${basePageUrl}fullList` : `${basePageUrl}shortList`}><ExpandIcon /></Link>,
|
|
}
|
|
}
|
|
const listWithTableProps = {
|
|
urls: urls,
|
|
translations: translations,
|
|
redirectUrls: redirectUrls,
|
|
initPagination: initPaginationDefault,
|
|
setSelectedRow: setSelectedRow,
|
|
}
|
|
const CreateFormProps = {
|
|
schemas: { create: getSchema.createSchema },
|
|
labels: getSchema.labels,
|
|
selectedRow: selectedRow,
|
|
}
|
|
const UpdateFormProps = {
|
|
rollbackTo: pageUrl,
|
|
schemas: { update: getSchema.updateSchema },
|
|
labels: getSchema.labels,
|
|
selectedRow: selectedRow,
|
|
}
|
|
const ViewFormProps = {
|
|
rollbackTo: pageUrl,
|
|
schemas: { view: getSchema.detailSchema },
|
|
selectedRow: selectedRow,
|
|
labels: getSchema.labels,
|
|
}
|
|
const shortAddProps = { ...listWithTableProps, schemas: { table: getSchema.shortSchema }, columns: { table: getSchema.shortColumns } }
|
|
const fullAddProps = { ...listWithTableProps, schemas: { table: getSchema.detailSchema }, columns: { table: getSchema.columns } }
|
|
return (
|
|
<div>
|
|
{/* {JSON.stringify(getSchema)} */}
|
|
{!isList && RenderBackToList}
|
|
{isList && mode === 'shortList' && <><TableComponent {...shortAddProps} /></>}
|
|
{isList && mode === 'fullList' && <><TableComponent {...fullAddProps} /></>}
|
|
{mode === 'create' && <CreateForm {...CreateFormProps} />}
|
|
{mode === 'update' && <UpdateForm {...UpdateFormProps} />}
|
|
{mode === 'view' && <ViewForm {...ViewFormProps} />}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export default aPage |