Files
tanami-admin-panel/src/Components/FormInputMain.jsx

120 lines
3.4 KiB
React
Raw Normal View History

2024-07-22 14:50:31 +05:30
import { Box, Button, Divider, Heading, Spinner } from "@chakra-ui/react";
2024-07-01 12:33:55 +05:30
import React from "react";
import FormField from "./FormField";
import { OPACITY_ON_LOAD } from "../Layout/animations";
2024-07-03 12:13:09 +05:30
import { ArrowBackIcon } from "@chakra-ui/icons";
2024-07-01 12:33:55 +05:30
const FormInputMain = ({
register,
2024-07-01 12:33:55 +05:30
groupedFields,
control,
errors,
onSubmit,
2024-07-08 12:22:27 +05:30
children,
onCancle,
2024-07-08 12:22:27 +05:30
submitTitle,
2024-07-05 15:28:02 +05:30
p,
w,
2024-07-22 14:50:31 +05:30
btnLoading
2024-07-01 12:33:55 +05:30
}) => {
return (
2024-07-09 19:05:08 +05:30
<Box mt={0} as="form" onSubmit={onSubmit}>
2024-07-01 12:33:55 +05:30
{Object.entries(groupedFields).map(([section, fields], index) => (
2024-07-09 19:05:08 +05:30
<Box key={section} mt={2}>
<Heading as="h6" size="xs" mx={5} my={0} fontWeight={"500"}>
2024-07-03 12:13:09 +05:30
{/* <ArrowBackIcon fontSize={'lg'} /> */}
2024-07-01 12:33:55 +05:30
{section}
</Heading>
<Box
2024-07-09 19:05:08 +05:30
as="span"
2024-07-01 12:33:55 +05:30
width={"100%"}
p={p ? p : 5}
2024-07-01 12:33:55 +05:30
display={"flex"}
flexWrap={"wrap"}
gap={4}
>
{fields.map(
(
{
label,
name,
id,
arabic,
type,
isRequired,
selectedImageData,
setSelectedImageData,
imageData,
handleImageChange,
removeImage,
placeHolder,
options,
helperText,
multiple,
width,
2024-07-01 12:33:55 +05:30
},
key
) => (
<FormField
id={id}
key={key}
label={label}
type={type}
name={name}
helperText={helperText ? helperText : undefined}
options={options ? options : undefined}
placeHolder={placeHolder ? placeHolder : undefined}
control={control}
errors={errors}
multiple={multiple}
isRequired={isRequired}
arabic={arabic}
selectedImageData={selectedImageData}
setSelectedImageData={setSelectedImageData}
imageData={imageData}
handleImageChange={handleImageChange}
removeImage={removeImage}
2024-07-05 12:07:52 +05:30
width={width}
2024-07-01 12:33:55 +05:30
/>
)
)}
</Box>
{index < Object.entries(groupedFields).length - 1 && <Divider />}
</Box>
))}
{children}
2024-07-09 19:05:08 +05:30
<Box display={"flex"} justifyContent={"end"} mt={2} >
<Box display={"flex"} justifyContent={"end"} p={2} w={"49%"} gap={4}>
{onCancle && (
<Button
size={"sm"}
width={w ? w : "44.5%"}
rounded={"sm"}
type="submit"
colorScheme="gray"
onClick={onCancle}
>
Cancel
</Button>
)}
2024-07-03 12:13:09 +05:30
<Button
2024-07-22 14:50:31 +05:30
isLoading={btnLoading}
2024-07-03 12:13:09 +05:30
size={"sm"}
width={w ? w : "44.5%"}
2024-07-03 12:13:09 +05:30
rounded={"sm"}
2024-07-22 14:50:31 +05:30
spinner={<Spinner size='sm' color='white' />}
2024-07-03 12:13:09 +05:30
type="submit"
2024-07-19 20:19:03 +05:30
colorScheme={"forestGreen"}
2024-07-03 12:13:09 +05:30
>
2024-07-08 12:22:27 +05:30
{submitTitle ? submitTitle : "Submit"}
2024-07-03 12:13:09 +05:30
</Button>
</Box>
2024-07-01 12:33:55 +05:30
</Box>
2024-07-09 19:05:08 +05:30
</Box>
2024-07-01 12:33:55 +05:30
);
};
export default FormInputMain;