Skip to content

Commit

Permalink
Replace FormModal with AddUserFormModal and remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinScitech committed Nov 14, 2024
1 parent 315e3fd commit 73d9911
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 124 deletions.
86 changes: 86 additions & 0 deletions frontend/src/components/crud/AddUserFormModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import React, { useState } from "react";
import { JSONSchema7 } from "json-schema";
import { Form } from "@rjsf/bootstrap-4";
import SimpleEntityAPIClient, {
SimpleEntityRequest,
SimpleEntityResponse,
} from "../../APIClients/SimpleEntityAPIClient";

const schema: JSONSchema7 = {
title: "Create Simple Entity",
description: "A simple form to test creating a simple entity",
type: "object",
required: [
"stringField",
"intField",
"stringArrayField",
"enumField",
"boolField",
],
properties: {
stringField: {
type: "string",
title: "String Field",
default: "UW Blueprint",
},
intField: {
type: "integer",
title: "Integer Field",
default: 2017,
},
stringArrayField: {
type: "array",
items: {
type: "string",
},
title: "String Array Field",
default: [],
},
enumField: {
type: "string",
enum: ["A", "B", "C", "D"],
title: "Enum Field",
default: "A",
},
boolField: {
type: "boolean",
title: "Boolean Field",
default: true,
},
},
};

const uiSchema = {
boolField: {
"ui:widget": "select",
},
};

const AddUserFormModal = (): React.ReactElement => {
const [data, setData] = useState<SimpleEntityResponse | null>(null);
const [formFields, setFormFields] = useState<SimpleEntityRequest | null>(
null,
);

if (data) {
return <p>Created! ✔️</p>;
}

const onSubmit = async ({ formData }: { formData: SimpleEntityRequest }) => {
const result = await SimpleEntityAPIClient.create({ formData });
setData(result);
};
return (
<Form
formData={formFields}
schema={schema}
uiSchema={uiSchema}
onChange={({ formData }: { formData: SimpleEntityRequest }) =>
setFormFields(formData)
}
onSubmit={onSubmit}
/>
);
};

export default AddUserFormModal;
105 changes: 0 additions & 105 deletions frontend/src/components/crud/FormModal.tsx

This file was deleted.

34 changes: 15 additions & 19 deletions frontend/src/components/pages/UserManagementPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import UserAPIClient from "../../APIClients/UserAPIClient";
import { User } from "../../types/UserTypes";
import MainPageButton from "../common/MainPageButton";
import FormModal from "../crud/FormModal";
import AddUserFormModal from "../crud/AddUserFormModal";

const UserManagementPage = (): React.ReactElement => {
const [users, setUsers] = useState<User[]>([]);
Expand All @@ -38,20 +38,20 @@ const UserManagementPage = (): React.ReactElement => {
}
};

const closeModal = () => {
setIsModalOpen(false);
};
// const closeModal = () => {
// setIsModalOpen(false);
// };

const handleSendInvite = (formData: {
firstName: string;
lastName: string;
phoneNumber: string;
email: string;
role: string;
}) => {
// eslint-disable-next-line no-console
console.log(`Invite sent to ${formData.email}`);
};
// const handleSendInvite = (formData: {
// firstName: string;
// lastName: string;
// phoneNumber: string;
// email: string;
// role: string;
// }) => {
// // eslint-disable-next-line no-console
// console.log(`Invite sent to ${formData.email}`);
// };

useEffect(() => {
getUsers();
Expand Down Expand Up @@ -82,11 +82,7 @@ const UserManagementPage = (): React.ReactElement => {
</Table>
</TableContainer>
<Button onClick={addUser}>+ Add a User</Button>
<FormModal
show={isModalOpen}
onClose={closeModal}
handleSendInvite={handleSendInvite}
/>
{isModalOpen && <AddUserFormModal />}
<MainPageButton />
</VStack>
</div>
Expand Down

0 comments on commit 73d9911

Please sign in to comment.