Skip to content

Commit

Permalink
Add. improve check box logic
Browse files Browse the repository at this point in the history
  • Loading branch information
jee-eun-k committed Feb 20, 2024
1 parent 1fb0d84 commit 578e852
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/pages/auth/signup/CheckTermsAndConditions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ const CheckTermsAndConditions = (props: any) => {
const [checked, setChecked] = useState([false, false, false, false, false]);
const [isNextButtonDisabled, setIsNextButtonDisabled] = useState(true);

const checkedLength = checked.length;

const handleCheckboxToggle = (idx: number) => () => {
const currentIndex = idx;
const newChecked: boolean[] = [...checked];
let newChecked: boolean[] = [...checked];
let newValue = !newChecked[idx];
let isRequiredCheck = false;

Expand All @@ -66,6 +68,14 @@ const CheckTermsAndConditions = (props: any) => {
newChecked.fill(newValue);
} else {
newChecked[idx] = newValue;
const falseChecked = newChecked.reduce((prev: number[], curr: any, idx: number) => {
return idx ? (curr ? [...prev] : [...prev, curr]) : [];
}, []);
if (!falseChecked.length) {
newChecked[0] = true;
} else if (falseChecked.length < checkedLength) {
newChecked[0] = false;
}
}
setChecked(newChecked);
isRequiredCheck = !(newChecked[1] && newChecked[2] && newChecked[3]);
Expand Down

0 comments on commit 578e852

Please sign in to comment.