-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace FormModal with AddUserFormModal and remove unused code
- Loading branch information
1 parent
315e3fd
commit 73d9911
Showing
3 changed files
with
101 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters