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

137 lines
3.9 KiB
React
Raw Normal View History

2024-07-26 13:38:48 +05:30
import { Box, Button, Divider, FormHelperText, Heading, Spinner, Text } 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-24 19:57:31 +05:30
btnLoading,
btnhidden,
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}
2024-07-24 19:58:15 +05:30
2024-07-01 12:33:55 +05:30
>
{fields.map(
(
{
label,
name,
id,
arabic,
type,
isRequired,
selectedImageData,
setSelectedImageData,
imageData,
handleImageChange,
removeImage,
placeHolder,
options,
helperText,
multiple,
width,
2024-07-24 19:58:15 +05:30
value,
2024-07-25 12:26:18 +05:30
handleInputChange,
align,
maxLength
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-26 13:38:48 +05:30
value={type === "date" ? null :value}
2024-07-24 19:58:15 +05:30
handleInputChange={handleInputChange}
align={align}
maxLength={maxLength}
2024-07-01 12:33:55 +05:30
/>
)
)}
</Box>
2024-07-26 13:38:48 +05:30
2024-07-01 12:33:55 +05:30
{index < Object.entries(groupedFields).length - 1 && <Divider />}
</Box>
))}
{children}
2024-07-24 19:57:31 +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-24 19:57:31 +05:30
{btnhidden ? (
""
) : (
<Button
isLoading={btnLoading}
size={"sm"}
width={w ? w : "44.5%"}
rounded={"sm"}
spinner={<Spinner size="sm" color="white" />}
type="submit"
colorScheme={"forestGreen"}
>
{submitTitle ? submitTitle : "Submit"}
</Button>
)}
2024-07-03 12:13:09 +05:30
</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;