Skip to content

Commit

Permalink
Merge branch 'main' into feat/MSSDK-1993-google-recaptcha
Browse files Browse the repository at this point in the history
  • Loading branch information
Saddage committed Jan 10, 2025
2 parents bdb1567 + 8f60d6f commit 818f0da
Show file tree
Hide file tree
Showing 29 changed files with 605 additions and 680 deletions.
82 changes: 0 additions & 82 deletions src/appRedux/planDetails.js

This file was deleted.

1 change: 0 additions & 1 deletion src/appRedux/rootReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ const rootReducer = combineReducers({
paymentDetails: paymentDetailsReducer,
paymentMethods: paymentMethodsReducer,
plan: planDetailsReducer,
// removed planDetails - to be checked if was needed
popup: popupReducer,
popupManager: popupManagerReducer,
publisherConfig: publisherConfigReducer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const AdditionalProfileInfo = ({
const newData: CustomSetting[] = data.map((setting) => {
return {
...setting,
answer: setting.answer ?? '',
value: setting.answer ? setting.answer : '',
values: setting.value
? setting.value.split(';').map((v) => v.trim())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { CustomCaptureSetting } from 'types/Capture.types';

export type CustomSetting = {
answer?: string;
key: string;
Expand All @@ -7,7 +9,7 @@ export type CustomSetting = {
};

export type AdditionalProfileInfoProps = {
data: CustomSetting[] | null;
data: CustomCaptureSetting[] | null;
isLoading: boolean;
updateCaptureOption: (option: { key: string; value: string }) => void;
};
20 changes: 9 additions & 11 deletions src/components/AddressDetails/AddressDetails.types.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { AddressCaptureSetting } from 'types/Capture.types';

export type Address = {
address: string | null;
address2: string | null;
city: string | null;
state: string | null;
postCode: string | null;
address: string;
address2: string;
city: string;
country: string;
state: string;
postCode: string;
};

export type AddressDetailsProps = {
data: {
answer: Address;
enabled: boolean;
key: string;
required: boolean;
};
data: AddressCaptureSetting;
isLoading?: boolean;
updateCaptureOption: (params: { key: string; value: Address }) => void;
};
32 changes: 13 additions & 19 deletions src/components/Capture/Capture.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Header from 'components/Header';
import Footer from 'components/Footer';
import Loader from 'components/Loader';
import getCaptureStatus from 'api/Customer/getCaptureStatus';
import { CaptureProps, CaptureSetting } from './Capture.types';
import { CaptureProps, CaptureSetting } from '../../types/Capture.types';
import CaptureForm from './CaptureForm/CaptureForm';

import {
Expand All @@ -15,25 +15,22 @@ import {

const noop = () => null;

const Capture = ({ settings = [], onSuccess = noop }: CaptureProps) => {
const Capture = ({ onSuccess = noop }: CaptureProps) => {
const { t } = useTranslation();
const [captureSettings, setCaptureSettings] = useState<CaptureSetting[]>([]);
const [isLoading, setIsLoading] = useState(true);

useEffect(() => {
if (settings.length) {
setCaptureSettings(settings);
setIsLoading(false);
} else {
getCaptureStatus().then((resp) => {
if (resp.responseData.shouldCaptureBeDisplayed === true) {
setCaptureSettings(resp.responseData.settings);
setIsLoading(false);
} else {
onSuccess();
}
});
}
getCaptureStatus().then(({ responseData }) => {
const { shouldCaptureBeDisplayed, settings } = responseData;

if (shouldCaptureBeDisplayed) {
setCaptureSettings(settings);
setIsLoading(false);
} else {
onSuccess();
}
});
}, []);

return (
Expand All @@ -47,10 +44,7 @@ const Capture = ({ settings = [], onSuccess = noop }: CaptureProps) => {
<CaptureTitle>
{t('capture.confirm-registration', 'Confirm Registration')}
</CaptureTitle>
<CaptureForm
settings={captureSettings || []}
onSuccess={onSuccess}
/>
<CaptureForm settings={captureSettings} onSuccess={onSuccess} />
</>
)}
</CaptureContentStyled>
Expand Down
78 changes: 46 additions & 32 deletions src/components/Capture/CaptureForm/CaptureForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useTranslation } from 'react-i18next';
import { updateCaptureAnswers } from 'api';
import { validateEmailField } from 'util/validators';
import { PHONE_NUMBER_REGEX } from 'util/regexConstants';
import { isCustomSetting } from 'util/capture';
import Input from 'components/Input';
import EmailInput from 'components/EmailInput';
import DateInput from 'components/DateInput';
Expand All @@ -12,27 +13,22 @@ import Button from 'components/Button';
import Loader from 'components/Loader';
import useInput from './useInput';
import {
CaptureProps,
CaptureSetting,
CaptureFormProps,
CustomCaptureSetting
} from '../Capture.types';
} from '../../../types/Capture.types';
import {
CaptureRowStyled,
CaptureBoxStyled,
CaptureQuestionStyled,
CaptureError
} from './CaptureFormStyled';

const isCustomSetting = (
setting: CaptureSetting
): setting is CustomCaptureSetting => setting.key.startsWith('custom_');

type CustomSetting = CustomCaptureSetting & {
values: Array<{ value: string; label: string }>;
error?: string | null;
};

const CaptureForm = ({ settings, onSuccess }: CaptureProps) => {
const CaptureForm = ({ settings, onSuccess }: CaptureFormProps) => {
const { t } = useTranslation();
const [processing, setProcessing] = useState(false);
const [customSettings, setCustomSettings] = useState<CustomSetting[]>([]);
Expand All @@ -54,36 +50,54 @@ const CaptureForm = ({ settings, onSuccess }: CaptureProps) => {
};

useEffect(() => {
for (let i = 0; i < settings.length; i += 1) {
const item = settings[i];
if (item.key === 'firstNameLastName' && item.answer) {
firstName.setValue(item.answer.firstName);
lastName.setValue(item.answer.lastName);
settings.forEach((setting) => {
const { answer, key } = setting;

if (!answer) {
return;
}
if (item.key === 'birthDate' && item.answer)
birthDate.setValue(item.answer);
if (item.key === 'companyName' && item.answer)
companyName.setValue(item.answer);
if (item.key === 'phoneNumber' && item.answer)
phoneNumber.setValue(item.answer);
if (item.key === 'address' && item.answer) {
address.setValue(item.answer.address);
address2.setValue(item.answer.address2);
city.setValue(item.answer.city);
state.setValue(item.answer.state);
postCode.setValue(item.answer.postCode);

switch (key) {
case 'firstNameLastName':
firstName.setValue(answer.firstName);
lastName.setValue(answer.lastName);
break;

case 'birthDate':
birthDate.setValue(answer);
break;

case 'companyName':
companyName.setValue(answer);
break;

case 'phoneNumber':
phoneNumber.setValue(answer);
break;

case 'address':
address.setValue(answer.address);
address2.setValue(answer.address2);
city.setValue(answer.city);
state.setValue(answer.state);
postCode.setValue(answer.postCode);
break;

default:
break;
}
}
});

const enabledCustomSettings: CustomSetting[] = settings.filter(
(item) => isCustomSetting(item) && item.enabled
(setting) => isCustomSetting(setting) && setting.enabled
) as CustomSetting[];

const transformedSettings: CustomSetting[] = enabledCustomSettings.map(
(item) => ({
...item,
value: item.answer ? item.answer : '',
values: isCustomSetting(item)
? item.value.split(';').map((i) => {
(setting) => ({
...setting,
value: setting.answer ? setting.answer : '',
values: isCustomSetting(setting)
? setting.value.split(';').map((i) => {
const value = i.trim();
const label = value;
return {
Expand Down
2 changes: 1 addition & 1 deletion src/components/CouponInput/CouponInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const CouponInput = ({
setIsOpen(true);
} else {
eventDispatcher(MSSDK_REDEEM_BUTTON_CLICKED, { coupon: value, source });
await onSubmit(value);
onSubmit(value);
}
};

Expand Down
Loading

0 comments on commit 818f0da

Please sign in to comment.