Skip to content

Commit

Permalink
feat: export page
Browse files Browse the repository at this point in the history
  • Loading branch information
harryle95 committed May 10, 2024
1 parent 07ff239 commit b61eda3
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 87 deletions.
1 change: 1 addition & 0 deletions src/components/page/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./factory";
23 changes: 0 additions & 23 deletions src/routes/investigation/investigation.stories.tsx

This file was deleted.

65 changes: 1 addition & 64 deletions src/routes/investigation/investigation.tsx
Original file line number Diff line number Diff line change
@@ -1,72 +1,9 @@
import { createStateBox, createStateBoxChildren } from "@ailiyah-ui/box";
import React from "react";
import { InvestigationType } from "./investigation.types";
import { Table, createHeaders, createBody } from "../../components/table/table";
import { Link, useLoaderData } from "react-router-dom";
import { FormComponent, createInputArray } from "../../components/form";
import { createPages } from "../../components/page";
import { InvestigationSchema } from "./investigation.types";
import { Form } from "react-router-dom";
import * as Button from "@ailiyah-ui/button";
import { styled } from "@ailiyah-ui/factory";
import { AbstractDataType, AbstractSchemaType } from "../../handlers";

let schema: InvestigationSchema = (await import("./data.json")).default;

const createPages = <T extends AbstractDataType>(
title: string,
schema: AbstractSchemaType<T>,
headers: Array<keyof T>
) => {
const components = createInputArray<T>(schema, ["id"]);
const THeader = createHeaders<T>({
title: "title",
headers: headers,
});
const DetailPage: React.FC<{}> = () => {
const data = useLoaderData() as Array<T> | null;
const TBody = createBody<T>({
bodyData: data,
fields: headers,
});
return (
<styled.div>
<styled.h1 themeName="PageTitle">{title}</styled.h1>
<Form id="search-form" role="search">
<styled.div>
<styled.input
id="title"
aria-label="Search title"
placeholder="Search"
type="search"
name="title"
themeName="PageSearchInput"
/>
<Link to={`/${title}/create`}>
<Button.AddButton type="button" tooltipContent="New" />
</Link>
</styled.div>
</Form>
<Table>
<THeader />
<TBody />
</Table>
</styled.div>
);
};
const CreatePage: React.FC<{}> = () => {
return <FormComponent method="POST">{components}</FormComponent>;
};
const UpdatePage: React.FC<{}> = () => {
const data = useLoaderData() as T | null;
const updateComponents = React.useMemo(
() => createInputArray(schema, [], data),
[JSON.stringify(data)]
);
return <FormComponent method="PUT">{updateComponents}</FormComponent>;
};
return [DetailPage, CreatePage, UpdatePage];
};

const [InvestigationList, InvestigationCreate, InvestigationUpdate] =
createPages<InvestigationType>("investigation", schema, [
"title",
Expand Down

0 comments on commit b61eda3

Please sign in to comment.