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

112 lines
3.2 KiB
React
Raw Normal View History

2024-07-01 12:33:55 +05:30
import { Box, Button, Divider, Heading } from "@chakra-ui/react";
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 = ({
groupedFields,
control,
errors,
onSubmit,
2024-07-03 12:13:09 +05:30
children,
2024-07-05 15:28:02 +05:30
p,
w
2024-07-01 12:33:55 +05:30
}) => {
return (
<form onSubmit={onSubmit}>
{Object.entries(groupedFields).map(([section, fields], index) => (
2024-07-05 12:07:52 +05:30
<Box key={section} mt={4} >
2024-07-03 12:13:09 +05:30
<Heading as="h6" size="xs" mx={5} fontWeight={'500'}>
{/* <ArrowBackIcon fontSize={'lg'} /> */}
2024-07-01 12:33:55 +05:30
{section}
</Heading>
<Box display={"flex"} gap={0}>
<Box
width={"100%"}
2024-07-05 15:28:02 +05:30
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,
2024-07-05 12:07:52 +05:30
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>
</Box>
{index < Object.entries(groupedFields).length - 1 && <Divider />}
</Box>
))}
{children}
2024-07-03 12:13:09 +05:30
<Box display={'flex'} justifyContent={'end'} mb={5}>
2024-07-05 15:28:02 +05:30
<Box display={"flex"} justifyContent={"space-around"} p={2} w={'49%'} gap={4}>
2024-07-03 12:13:09 +05:30
<Button
size={"sm"}
2024-07-05 15:28:02 +05:30
width={w?w:"44.5%"}
2024-07-03 12:13:09 +05:30
rounded={"sm"}
type="submit"
colorScheme='gray'
>
Cancel
</Button>
<Button
size={"sm"}
2024-07-05 15:28:02 +05:30
width={w?w:"44.5%"}
2024-07-03 12:13:09 +05:30
rounded={"sm"}
type="submit"
colorScheme="green"
>
Submit
</Button>
</Box>
2024-07-01 12:33:55 +05:30
</Box>
</form>
);
};
export default FormInputMain;