Skip to content

Commit

Permalink
fix edge cases in step switching, delete prints
Browse files Browse the repository at this point in the history
  • Loading branch information
SimeJadrijev committed Jan 31, 2025
1 parent 5cf68fc commit 3227939
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 16 deletions.
20 changes: 11 additions & 9 deletions apps/app/src/components/Checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ type CheckboxProps = {
} & Omit<React.HTMLProps<HTMLInputElement>, 'onChange'>;
export const Checkbox = ({ name, checked, label, onChange }: CheckboxProps) => {
return (
<div className={c.checkbox}>
<input
type='checkbox'
checked={checked}
name={name}
onChange={onChange}
/>
<label>{label}</label>
</div>
<>
<div className={c.checkbox}>
<input
type='checkbox'
checked={checked}
name={name}
onChange={onChange}
/>
<label>{label}</label>
</div>
</>
);
};
2 changes: 1 addition & 1 deletion apps/app/src/components/ProgressBar/ProgressBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const ProgressBar = ({
const handleStepClick = (clickedStep: number) => {
const isGoingBackwards = clickedStep <= currentStep;
const isGoingForward = clickedStep === currentStep + 1;
console.log(isStepValid(currentStep));

if (isGoingBackwards) {
setCurrentStep(clickedStep);
} else if (isGoingForward && isStepValid(currentStep)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,22 @@ export const FirstStepRegistrationForm = ({
}
};

const allFieldsAreFilled = () => {
if (
(userData.firstName != '' &&
userData.lastName !== '' &&
userData.email !== '',
userData.password !== '',
userData.repeatedPassword !== '')
) {
return true;
}

return false;
};

useEffect(() => {
if (isSubmitted) {
if (isSubmitted || allFieldsAreFilled()) {
validateFirstStep();
}
}, [isSubmitted, userData]);

Check warning on line 91 in apps/app/src/components/RegistrationForms/FirstStepRegistrationForm/FirstStepRegistrationForm.tsx

View workflow job for this annotation

GitHub Actions / Run ESLint (app)

React Hook useEffect has missing dependencies: 'allFieldsAreFilled' and 'validateFirstStep'. Either include them or remove the dependency array
Expand Down Expand Up @@ -124,15 +138,15 @@ export const FirstStepRegistrationForm = ({
checked={userData.newsletterEnabled}
name={UserDataFields.NewsletterEnabled}
onChange={handleCheckboxChange}
error={errors[1]?.termsAndConditionsEnabled}
error={errors[1]?.newsletterEnabled}
key={1}
/>
<Checkbox
label='Želim primati novosti o tvrtkama i otvorenim radnim pozicijama.'
checked={userData.companiesNewsEnabled}
name={UserDataFields.CompaniesNewsEnabled}
onChange={handleCheckboxChange}
error={errors[1]?.termsAndConditionsEnabled}
error={errors[1]?.companiesNewsEnabled}
key={2}
/>
<Checkbox
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const GeneralRegistrationForm = () => {
};

const { isStepValid } = useRegistration();

const handleRegistrationClick = () => {
switch (currentStep) {
case 1:
Expand All @@ -62,7 +63,6 @@ export const GeneralRegistrationForm = () => {
let nextStep = currentStep + 1;

Check failure on line 63 in apps/app/src/components/RegistrationForms/GeneralRegistrationForm/GeneralRegistrationForm.tsx

View workflow job for this annotation

GitHub Actions / Run ESLint (app)

'nextStep' is never reassigned. Use 'const' instead
setCurrentStep(nextStep);
}
console.log('currentStep: ', currentStep);
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,20 @@ export const SecondStepRegistrationForm = ({
}
};

const allFieldsAreFilled = () => {
if (
userData.phoneNumber !== '' &&
userData.birthYear !== null &&
userData.educationDegree !== null &&
userData.occupation !== null
) {
return true;
}
return false;
};

useEffect(() => {
if (isSubmitted) {
if (isSubmitted || allFieldsAreFilled()) {
validateSecondStep();
}
}, [isSubmitted, userData]);

Check warning on line 96 in apps/app/src/components/RegistrationForms/SecondStepRegistrationForm/SecondStepRegistrationForm.module.tsx

View workflow job for this annotation

GitHub Actions / Run ESLint (app)

React Hook useEffect has missing dependencies: 'allFieldsAreFilled' and 'validateSecondStep'. Either include them or remove the dependency array
Expand Down
1 change: 0 additions & 1 deletion apps/app/src/providers/RegistrationContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export const RegistrationProvider = ({ children }: { children: ReactNode }) => {
const [errors, setErrors] = useState<Record<number, RegistrationFormErrors>>(
{},
);
console.log(errors);

const setStepErrors = (
step: number,
Expand Down

0 comments on commit 3227939

Please sign in to comment.