+
{children}
{icon && (
{text};
+}
+
+FormHeader.propTypes = {
+ text: PropTypes.string.isRequired
+}
+
+export default FormHeader;
diff --git a/src/components/FormInput.jsx b/src/components/FormInput.jsx
index 8cf296c..cc550ea 100644
--- a/src/components/FormInput.jsx
+++ b/src/components/FormInput.jsx
@@ -1,8 +1,11 @@
import PropTypes from "prop-types";
import { motion, AnimatePresence } from "motion/react";
+import clsx from "clsx";
+
function FormInput({
value,
onChange,
+ placeholder,
valid = true,
maxLength = 17,
readOnly = false,
@@ -14,10 +17,14 @@ function FormInput({
{!valid && (
@@ -44,6 +51,7 @@ FormInput.propTypes = {
type: PropTypes.string,
maxLength: PropTypes.number,
valid: PropTypes.bool,
+ placeholder: PropTypes.string,
};
export default FormInput;
diff --git a/src/components/FormSelect.jsx b/src/components/FormSelect.jsx
index db7022a..f779b68 100644
--- a/src/components/FormSelect.jsx
+++ b/src/components/FormSelect.jsx
@@ -1,40 +1,32 @@
import PropTypes from "prop-types";
-import { motion, AnimatePresence } from "motion/react";
+import { AnimatePresence } from "motion/react";
+import clsx from "clsx";
+import FieldError from "./FieldError";
function FormSelect({ value, onChange, options, className, valid = true }) {
return (
-
-
- {!valid && (
-
- Invalid Value
-
+
+
+ {!valid && }
-
+
);
}
diff --git a/src/components/ProductModal.jsx b/src/components/ProductModal.jsx
new file mode 100644
index 0000000..c17619f
--- /dev/null
+++ b/src/components/ProductModal.jsx
@@ -0,0 +1,35 @@
+import { motion } from "motion/react";
+import ProductListTable from "./ProductListTable";
+import PropTypes from "prop-types";
+
+function ProductModal({ productInfo, handleProductSelect }) {
+ return (
+
+
+ Select Product
+
+
+
+ );
+}
+
+ProductModal.propTypes = {
+ productInfo: PropTypes.object.isRequired,
+ handleProductSelect: PropTypes.func.isRequired,
+};
+
+export default ProductModal;
diff --git a/src/pages/AccountCreation.jsx b/src/pages/AccountCreation.jsx
index 6bf371d..d7a94cd 100644
--- a/src/pages/AccountCreation.jsx
+++ b/src/pages/AccountCreation.jsx
@@ -1,8 +1,6 @@
import { AnimatePresence } from "motion/react";
-import clsx from "clsx";
-import { PackageSearch, Copy, UserSearch } from "lucide-react";
+import { PackageSearch, UserSearch } from "lucide-react";
import { useState } from "react";
-import { motion } from "motion/react";
import FormBox from "../components/FormBox";
import { useTranslation } from "react-i18next";
import FormField from "../components/FormField";
@@ -10,17 +8,14 @@ import FormInput from "../components/FormInput";
import FormSelect from "../components/FormSelect";
import Button from "../components/Button";
import productInfo from "../util/productList";
-import ProductListTable from "../components/ProductListTable";
+import Notification from "../components/Notification";
+import ProductModal from "../components/ProductModal";
+import FormHeader from "../components/FormHeader";
function AccountCreation() {
const { t } = useTranslation();
- const [notification] = useState({
- visible: false,
- message: "",
- type: "",
- });
+ const [notification] = useState({ message: "", type: "" });
const [showProductModal, setShowProductModal] = useState(false);
- const [submitting] = useState(false);
const [accountDetails, setAccountDetails] = useState({
productCode: "",
interestCategory: "",
@@ -48,6 +43,8 @@ function AccountCreation() {
const newAccountDetails = { ...accountDetails };
newAccountDetails.productCode = product.productCode;
newAccountDetails.interestCategory = product.interestCategory;
+ newAccountDetails.productCodeValid = true;
+ newAccountDetails.interestCategoryValid = true;
setAccountDetails(newAccountDetails);
setShowProductModal(false);
};
@@ -181,36 +178,8 @@ function AccountCreation() {
}
console.log("Form is valid", accountDetails);
};
- const renderProductModal = () => {
- return (
-
- {showProductModal && (
-
-
- Select Product
-
-
-
- )}
-
- );
- };
- const renerField = (field) => {
+ const renderField = (field) => {
const commonProps = {
value: accountDetails[field.name],
valid: accountDetails[`${field.name}Valid`],
@@ -221,7 +190,6 @@ function AccountCreation() {
setAccountDetails(newAccountDetails);
},
maxLength: field.maxLength,
- className: clsx(!accountDetails[`${field.name}Valid`] && "border-error"),
};
return (
@@ -242,59 +210,32 @@ function AccountCreation() {
return (
- {notification.visible && (
-
- {notification.message.split(":").map((msg, index) => {
- return index === 1 ? (
-
- {msg}
-
- ) : (
- {msg}
- );
- })}
-
-
+ {notification.message !== "" && }
+
+
+
+ {showProductModal && (
+
)}
- {renderProductModal()}
-
+
+
-
- Account Details
-
- {accountDetailsFields.map(renerField)}
+
+ {accountDetailsFields.map(renderField)}
-
- Additional Details
-
- {additionalDetailsFields.map(renerField)}
+
+ {additionalDetailsFields.map(renderField)}
-
+
+
);
}
diff --git a/src/pages/LockersRegistration.jsx b/src/pages/LockersRegistration.jsx
index 8f72406..55ce2f3 100644
--- a/src/pages/LockersRegistration.jsx
+++ b/src/pages/LockersRegistration.jsx
@@ -1,25 +1,23 @@
import { useLocation } from "react-router-dom";
import { useState } from "react";
-import clsx from "clsx";
+import { useToast } from "../hooks/useToast";
+import { useLoading } from "../hooks/useLoading";
import FormBox from "../components/FormBox";
import Button from "../components/Button";
-import { useToast } from "../hooks/useToast";
import { lockerService } from "../services/locker.service";
import { AnimatePresence } from "motion/react";
-import { useLoading } from "../hooks/useLoading";
import Notification from "../components/Notification";
+import FormField from "../components/FormField";
+import FormInput from "../components/FormInput";
+import FormSelect from "../components/FormSelect";
function LockersRegistration() {
const location = useLocation();
- const showToast = useToast();
const { setIsLoading } = useLoading();
- const noOfLockers = location.state?.noOfLockers;
+ const [notification, setNotification] = useState({ message: "", type: "" });
+
+ const noOfLockers = location.state?.noOfLockers;
const cabinetId = location.state?.cabinetId;
- const [submitting, setSubmitting] = useState(false);
- const [notification, setNotification] = useState({
- message: "",
- type: "",
- });
const initLockers = Array(noOfLockers ? parseInt(noOfLockers) : 0)
.fill()
@@ -31,12 +29,14 @@ function LockersRegistration() {
sizeValid: true,
keyIdValid: true,
}));
+
const [lockerValues, setLockerValues] = useState(initLockers);
- if(!location.state) {
- return <>>
+
+ if (!location.state) {
+ return <>>;
}
+
const handleSubmit = async (e) => {
- console.log("submitting");
e.preventDefault();
const idRegex = /^[A-Z]{2}[0-9]{4}$/;
let valid = true;
@@ -92,16 +92,10 @@ function LockersRegistration() {
setLockerValues(newValues);
if (!valid) {
- const errorMessage =
- duplicateLockerIds.length || duplicateKeyIds.length
- ? "Please ensure all IDs are unique."
- : "Inavlid Ids";
- showToast(errorMessage, "error");
return;
}
try {
- setSubmitting(true);
setIsLoading(true);
const response = await lockerService.registerLockers(
cabinetId,
@@ -120,84 +114,50 @@ function LockersRegistration() {
return;
} finally {
setIsLoading(false);
- setSubmitting(false);
}
};
const lockerDetails = lockerValues.map((locker, index) => {
return (
-
-
-
-
+ {
+ onChange={ e => {
const newValues = [...lockerValues];
- newValues[index] = {
- ...newValues[index],
- id: e.target.value.toUpperCase(),
- idValid: true,
- };
+ newValues[index].id = e.target.value;
+ newValues[index].idValid = true;
setLockerValues(newValues);
}}
- placeholder="Locker ID"
- type="text"
- maxLength={6}
+ valid={locker.idValid}
+ placeholder={"Locker Id"}
/>
-
-
-
- {
- const newValues = [...lockerValues];
- newValues[index] = {
- ...newValues[index],
- keyId: e.target.value.toUpperCase(),
- keyIdValid: true,
- };
- setLockerValues(newValues);
- }}
- placeholder="Key ID"
- type="text"
- maxLength={6}
+ valid={locker.sizeValid}
+ options={[
+ {label: 'Small', value: '1'},
+ {label: 'Medium', value: '2'},
+ {label: 'Large', value: '3'}
+ ]}
/>
-
+
{
+ const newValues = [...lockerValues];
+ newValues[index].keyId = e.target.value;
+ newValues[index].keyIdValid = true;
+ setLockerValues(newValues);
+ }}
+ valid={locker.keyIdValid}
+ placeholder={"Locker Key Id"}
+ />
+
);
});
@@ -210,13 +170,12 @@ function LockersRegistration() {
{notification.type === "success" && (
)}
-
+
{cabinetId}
{lockerDetails}