Skip to content

Commit

Permalink
use FormField components for GeneralDetails section
Browse files Browse the repository at this point in the history
  • Loading branch information
rithviknishad committed Jan 2, 2023
1 parent ac5b874 commit a4c7b7b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 25 deletions.
14 changes: 8 additions & 6 deletions src/Components/Common/components/Switch.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { FieldLabel } from "../../Form/FormFields/FormField";
import { ErrorHelperText } from "../HelperInputFields";

type SwitchProps<T> = {
Expand All @@ -16,12 +17,13 @@ type SwitchProps<T> = {
export default function SwitchV2<T>(props: SwitchProps<T>) {
return (
<div className={props.className}>
{props.label && (
<label htmlFor="is_working" className="mb-3">
{props.label}
{props.required && " *"}
</label>
)}
<FieldLabel
htmlFor={props.name}
required={props.required}
className="mb-3"
>
{props.label}
</FieldLabel>
<ul role="list" className="flex">
{props.options.map((option, index) => {
const selected = option === props.value;
Expand Down
31 changes: 12 additions & 19 deletions src/Components/Facility/AssetCreate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import { Cancel, Submit } from "../Common/components/ButtonV2";
import DateInputV2 from "../Common/DateInputV2";
import AutocompleteFormField from "../Form/FormFields/Autocomplete";
import { SelectFormField } from "../Form/FormFields/SelectFormField";
import TextFormField from "../Form/FormFields/TextFormField";
import TextAreaFormField from "../Form/FormFields/TextAreaFormField";
const Loading = loadable(() => import("../Common/Loading"));

const formErrorKeys = [
Expand Down Expand Up @@ -511,13 +513,13 @@ const AssetCreate = (props: AssetProps) => {

{/* Asset Name */}
<div className="col-span-6" ref={fieldRef["name"]}>
<TextInputFieldV2
id="asset-name"
<TextFormField
name="name"
label="Asset Name"
required
value={name}
onValueChange={setName}
onChange={({ value }) => setName(value)}
error={state.errors.name}
required
/>
</div>

Expand Down Expand Up @@ -590,23 +592,14 @@ const AssetCreate = (props: AssetProps) => {

{/* Description */}
<div className="col-span-6">
<label htmlFor="asset-description">
Describe the asset
</label>
<textarea
id="asset-description"
className={
"mt-2 block w-full input" +
((state.errors.description && " border-red-500") || "")
}
name="asset-description"
placeholder="Eg. Details about the equipment"
<TextAreaFormField
name="asset_description"
label="Description"
placeholder="Details about the equipment"
value={description}
onChange={(e: React.ChangeEvent<HTMLTextAreaElement>) =>
setDescription(e.target.value)
}
onChange={({ value }) => setDescription(value)}
error={state.errors.description}
/>
<ErrorHelperText error={state.errors.description} />
</div>

{/* Divider */}
Expand Down

0 comments on commit a4c7b7b

Please sign in to comment.