Validation change

This commit is contained in:
F Shrabon 2024-10-01 18:45:04 +06:00
parent f311f3ade5
commit a2aa637b94
6 changed files with 45 additions and 21 deletions

1
.gitignore vendored
View File

@ -6,6 +6,7 @@ yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
/*.zip
node_modules
dist

View File

@ -9,6 +9,7 @@ interface Option {
brn: string;
};
value: string;
disabled?: boolean;
}
interface DropdownProps {
@ -27,6 +28,7 @@ const ReactDoesMultiSelectInput: React.FC<DropdownProps> = ({
onChange,
hidePills = false,
disableSelectAll = false,
disabled,
}) => {
const showPillsSection = !hidePills;
const [isOpen, setIsOpen] = useState<boolean>(false);
@ -131,7 +133,9 @@ const ReactDoesMultiSelectInput: React.FC<DropdownProps> = ({
</div>
<div
className="group flex items-center bg-slate-300 hover:bg-red-200 rounded-tr rounded-br px-[2px]"
onClick={(event) => handleOptionClick(event, option)}
onClick={(event) =>
disabled ? null : handleOptionClick(event, option)
}
>
<svg
xmlns="http://www.w3.org/2000/svg"
@ -206,7 +210,11 @@ const ReactDoesMultiSelectInput: React.FC<DropdownProps> = ({
{filteredOptions.map((option) => (
<div
key={option.value}
className={`block w-full text-left px-4 py-2 text-sm border-b last:border-b-0 hover:cursor-pointer ${
className={`block w-full text-left px-4 py-2 text-sm border-b last:border-b-0 ${
option?.disabled
? "cursor-not-allowed"
: "cursor-pointer"
} ${
selectedOptions.some(
(selectedOption) =>
selectedOption.value === option.value
@ -215,7 +223,11 @@ const ReactDoesMultiSelectInput: React.FC<DropdownProps> = ({
: "hover:bg-gray-100"
}`}
role="menuitem"
onClick={(event) => handleOptionClick(event, option)}
onClick={(event) =>
option.disabled
? null
: handleOptionClick(event, option)
}
>
<div className="flex justify-between items-center">
<div className="flex items-center gap-4">
@ -225,6 +237,7 @@ const ReactDoesMultiSelectInput: React.FC<DropdownProps> = ({
(selectedOption) =>
selectedOption.value === option.value
)}
disabled={option.disabled}
/>
<div className="space-y-1">
<p> {option.label.name}</p>

View File

@ -43,8 +43,7 @@ const EditBeneficiaryFormModal: React.FC<EditBeneficiaryFormModalProps> = ({
const schema = YUP.object()
.shape({
dob: YUP.date().required("Date of birth is required"),
relation: YUP.date().required("Relation is required"),
relation: YUP.string().required("Relation is required"),
type: YUP.string().oneOf(["nid", "brn"]).required("Type is required"),
mobile: YUP.string()
.required("Phone number required")
@ -98,13 +97,13 @@ const EditBeneficiaryFormModal: React.FC<EditBeneficiaryFormModalProps> = ({
<Formik
initialValues={{
...selectedData,
nid: selectedData.nid ?? "",
brn: selectedData.brn ?? "",
type: selectedData.brn ? "brn" : "nid",
}}
validationSchema={schema}
onSubmit={(values) => {
const {
brn,
nid,
firstNameBN,
firstName,
lastName,
@ -117,8 +116,6 @@ const EditBeneficiaryFormModal: React.FC<EditBeneficiaryFormModalProps> = ({
const formData = {
...values,
brn,
nid,
firstNameBN,
firstName,
lastName,
@ -135,8 +132,8 @@ const EditBeneficiaryFormModal: React.FC<EditBeneficiaryFormModalProps> = ({
dob: formData.dob,
mobile: formData.mobile,
passport: formData.passport,
brn,
nid,
brn: formData.brn,
nid: formData.nid,
firstNameBN,
firstName,
lastName,
@ -168,10 +165,15 @@ const EditBeneficiaryFormModal: React.FC<EditBeneficiaryFormModalProps> = ({
isRequired
name="relation"
options={[
{
value: "self",
label: "Self",
},
{
value: "father",
label: "Father",
},
{
value: "mother",
label: "Mother",

View File

@ -154,7 +154,7 @@ const SaveForm = ({
email: YUP.string()
.email("Invalid email format")
.required("Email is required"),
gender: YUP.string().required("Gender is required"),
brn: YUP.string(),
village: YUP.string().required("Village is required"),
firstNameBN: YUP.string(),
@ -165,7 +165,6 @@ const SaveForm = ({
"পাসপোর্টে কমপক্ষে একটি অক্ষর, একটি সংখ্যা থাকতে হবে এবং কমপক্ষে ৮ অক্ষর দীর্ঘ হতে হবে"
)
.optional(),
motherName: YUP.string().required("Mothers name is required"),
nid: YUP.string(),
})
.test(
@ -278,8 +277,8 @@ const SaveForm = ({
<p className="font-medium underline">Location</p>
<OcvLocationManagement />
<p className="font-medium underline">Address</p>
<FormikText label="Village" name="village" />
<FormikText label="House No" name="hhNumber" />
<FormikText label="Village" name="village" isRequired />
<FormikText label="House No" name="hhNumber" isRequired />
<p className="font-medium underline">Personal Information</p>
<VerifyIdentification
error={errorFindByNidOrBrn}
@ -393,8 +392,8 @@ const SaveForm = ({
/>
)}
<FormikText label="Passport" name="passport" />
<FormikText label="Email" name="email" />
<FormikText label="Mobile" name="mobile" />
<FormikText label="Email" name="email" isRequired />
<FormikText label="Mobile" name="mobile" isRequired />
<FormikText
label="Vaccination Date"
name="vaccinatedDate"
@ -407,9 +406,9 @@ const SaveForm = ({
<SubmitBtn
title="Save"
loading={isLoading}
// disabled={
// isParent && !!(Object.keys(dataFindByNidOrBrn).length === 0)
// }
disabled={
isParent && !!(Object.keys(dataFindByNidOrBrn).length === 0)
}
/>
</div>
)}

View File

@ -11,6 +11,10 @@ import FormikRadio from "../../../components/molecules/FormikRadio";
import FormikText from "../../../components/molecules/FormikText";
import { YUP as Yup } from "../../../constant/yup";
import Sidebar from "../../../layouts/Sidebar";
import {
calculateDaysFromDOB,
calculateFutureDate,
} from "../../../utils/dateFunctions";
import OcvLocationManagement from "../components/OcvLocationManagement";
const initialFormValues = {
@ -225,7 +229,7 @@ const Dose2Form = () => {
)}
<div className="flex justify-around items-center gap-4">
<SubmitBtn title="Searchss" loading={isLoadingDoses} />
<SubmitBtn title="Search" loading={isLoadingDoses} />
</div>
</Form>
</fieldset>
@ -261,6 +265,7 @@ const Dose2Form = () => {
mobile: string;
nid: string;
brn: string;
vaccinatedDate: string;
}) => ({
value: String(item.id),
label: {
@ -269,6 +274,10 @@ const Dose2Form = () => {
nid: item.nid,
brn: item.brn,
},
disabled:
calculateDaysFromDOB(
calculateFutureDate(item?.vaccinatedDate, 45)
) <= 45,
})
)}
/>

Binary file not shown.