Skip to content

Commit

Permalink
feat(auth): skip personal details when optional
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristiaanScheermeijer committed Aug 2, 2021
1 parent b6e68dc commit 4d676a9
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/containers/AccountModal/forms/PersonalDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React, { useCallback, useEffect, useState } from 'react';
import type { CaptureCustomAnswer, CleengCaptureQuestionField, PersonalDetailsFormData } from 'types/account';
import { useTranslation } from 'react-i18next';
import { useHistory } from 'react-router';
Expand Down Expand Up @@ -27,6 +27,16 @@ const PersonalDetails = () => {
const fields = data ? Object.fromEntries(data.settings.map((item) => [item.key, item])) : {};
const questions = data ? data.settings.filter((item) => !!(item as CleengCaptureQuestionField).question) as CleengCaptureQuestionField[] : [];

const nextStep = useCallback(() => {
const hasOffers = config.json?.cleengMonthlyOffer && config.json?.cleengYearlyOffer;

history.replace(addQueryParam(history, 'u', hasOffers ? 'choose-offer' : 'welcome'));
}, [history, config]);

useEffect(() => {
if (data && (!data.isCaptureEnabled || !data.shouldCaptureBeDisplayed)) nextStep();
}, [data, nextStep]);

const initialValues: PersonalDetailsFormData = {
firstName: '',
lastName: '',
Expand Down Expand Up @@ -87,9 +97,7 @@ const PersonalDetails = () => {
const customAnswers = questions.map(question => ({ question: question.question, questionId: question.key, value: questionValues[question.key] } as CaptureCustomAnswer));
await updateCaptureAnswers(removeEmpty({ ...formData, customAnswers }));

const hasOffers = config.json?.cleengMonthlyOffer && config.json?.cleengYearlyOffer;

history.push(addQueryParam(history, 'u', hasOffers ? 'choose-offer' : 'welcome'));
nextStep();
} catch (error: unknown) {
if (error instanceof Error) {
setErrors({ form: error.message });
Expand Down

0 comments on commit 4d676a9

Please sign in to comment.