Skip to content

Commit

Permalink
fix: code review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
mirovladimitrovski committed Nov 10, 2023
1 parent 1af1011 commit 631f342
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 32 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"dependencies": {
"@adyen/adyen-web": "^5.42.1",
"@codeceptjs/allure-legacy": "^1.0.2",
"@inplayer-org/inplayer.js": "^3.13.19",
"@inplayer-org/inplayer.js": "^3.13.21",
"classnames": "^2.3.1",
"date-fns": "^2.28.0",
"dompurify": "^2.3.8",
Expand Down
34 changes: 15 additions & 19 deletions src/components/CustomRegisterField/CustomRegisterField.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type FC, type ChangeEventHandler, type ReactNode, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import type { GetRegisterFieldOption } from '@inplayer-org/inplayer.js';
import type { RegisterFieldOptions } from '@inplayer-org/inplayer.js';

import type { CustomRegisterFieldVariant } from '#types/account';
import { isTruthyCustomParamValue, testId } from '#src/utils/common';
Expand All @@ -22,34 +22,30 @@ type Props = {
helperText: string;
disabled: boolean;
required: boolean;
options: GetRegisterFieldOption;
options: RegisterFieldOptions;
}>;

export type CustomRegisterFieldCommonProps = Props;

export const CustomRegisterField: FC<Props> = ({ type, value = '', ...props }) => {
export const CustomRegisterField: FC<Props> = ({ type, value = '', options, ...props }) => {
const { t, i18n } = useTranslation();

const optionsList = useMemo(() => {
switch (type) {
case 'country':
case 'us_state': {
const codes = Object.keys(i18n.getResourceBundle(i18n.language, type));
if (type && ['country', 'us_state'].includes(type)) {
const codes = Object.keys(i18n.getResourceBundle(i18n.language, type));

return codes.map((code) => ({
value: code,
label: t(`${type}:${code}`),
}));
}
default: {
if (props.options) {
return Object.entries(props.options).map(([value, label]) => ({ value, label }));
}
return codes.map((code) => ({
value: code,
label: t(`${type}:${code}`),
}));
}

return [];
}
if (options) {
return Object.entries(options).map(([value, label]) => ({ value, label }));
}
}, [t, type, props.options, i18n]);

return [];
}, [t, type, options, i18n]);

switch (type) {
case 'input':
Expand Down
3 changes: 1 addition & 2 deletions src/services/inplayer.account.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ export const getPublisherConsents: GetPublisherConsents = async (config) => {
label: field.label,
placeholder: field.placeholder,
required: field.required,
// todo: field.option type in SDK is incorrect, remove the type casting after fixing that
options: field.options as unknown as Record<string, string>,
options: field.options,
version: '1',
...(field.type === 'checkbox'
? {
Expand Down
12 changes: 6 additions & 6 deletions src/utils/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ const formatConsentValues = (publisherConsents: Consent[] | null = [], customerC
return {};
}

const values: Record<string, string | boolean> = {};

publisherConsents?.forEach((publisherConsent) => {
const values = publisherConsents?.reduce((acc, publisherConsent) => {
const consent = customerConsents?.find((customerConsent) => customerConsent.name === publisherConsent.name);

if (consent) {
const value = publisherConsent.isCustomRegisterField === true ? consent.value ?? '' : consent.state === 'accepted';
values[publisherConsent.name] = value;
const value = publisherConsent.isCustomRegisterField ? consent.value ?? '' : consent.state === 'accepted';
acc[publisherConsent.name] = value;
}
});

return acc;
}, {} as Record<string, string | boolean>);

return values;
};
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1481,10 +1481,10 @@
resolved "https://registry.yarnpkg.com/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz#b520529ec21d8e5945a1851dfd1c32e94e39ff45"
integrity sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==

"@inplayer-org/inplayer.js@^3.13.19":
version "3.13.19"
resolved "https://registry.yarnpkg.com/@inplayer-org/inplayer.js/-/inplayer.js-3.13.19.tgz#064069a83f6d6241067071e846a7ecf60d9f8135"
integrity sha512-KyURtkjOt2cuKzGJfxrc4xMTkvqywWh81u6MpbMmpCOOYnGBsb2z92Uop4M/bVc24gbIGzAqpTttFqruOJLR6w==
"@inplayer-org/inplayer.js@^3.13.21":
version "3.13.21"
resolved "https://registry.yarnpkg.com/@inplayer-org/inplayer.js/-/inplayer.js-3.13.21.tgz#01ca8c9096fc37f043d1ae2ab718c4fc04085a3d"
integrity sha512-M8HQ0rEUd3jVyWpReMH2rtmUTl2aF3lXa9n91UBRvAj+Bgb8Mux6DxGwHmG0uOT8fGUVxqHTa26yYWEJYTvYNA==
dependencies:
aws-iot-device-sdk "^2.2.6"
axios "^0.21.2"
Expand Down

0 comments on commit 631f342

Please sign in to comment.