Skip to content

Commit

Permalink
fix: rename functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mirovladimitrovski committed Oct 3, 2023
1 parent 26539ad commit ad20660
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/components/Account/Account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import Checkbox from '#components/Checkbox/Checkbox';
import HelperText from '#components/HelperText/HelperText';
import CustomRegisterField from '#components/CustomRegisterField/CustomRegisterField';
import useToggle from '#src/hooks/useToggle';
import { formatConsentsFromValues, formatConsents, formatConsentValues, noEmptyStringEntries, formatCrfEntries } from '#src/utils/collection';
import { formatConsentsFromValues, formatConsents, formatConsentValues, isNotEmptyStringEntry, formatCrfEntry } from '#src/utils/collection';
import { addQueryParam } from '#src/utils/location';
import { useAccountStore } from '#src/stores/AccountStore';
import { isTruthy, logDev } from '#src/utils/common';
Expand Down Expand Up @@ -263,7 +263,7 @@ const Account = ({ panelClassName, panelHeaderClassName, canUpdateEmail = true }
label: t('account.terms_and_tracking'),
saveButton: t('account.update_consents'),
onSubmit: (values) => {
const cleanConsentValues = Object.fromEntries(Object.entries(values.consentsValues).filter(noEmptyStringEntries).map(formatCrfEntries));
const cleanConsentValues = Object.fromEntries(Object.entries(values.consentsValues).filter(isNotEmptyStringEntry).map(formatCrfEntry));
return updateConsents(formatConsentsFromValues(publisherConsents, { ...cleanConsentValues, terms: true }), cleanConsentValues);
},
content: (section) => (
Expand All @@ -286,7 +286,7 @@ const Account = ({ panelClassName, panelHeaderClassName, canUpdateEmail = true }
label: t('account.other_registration_details'),
saveButton: t('account.update_consents'),
onSubmit: (values) => {
const cleanConsentValues = Object.fromEntries(Object.entries(values.consentsValues).filter(noEmptyStringEntries).map(formatCrfEntries));
const cleanConsentValues = Object.fromEntries(Object.entries(values.consentsValues).filter(isNotEmptyStringEntry).map(formatCrfEntry));
return updateConsents(formatConsentsFromValues(publisherConsents, cleanConsentValues), cleanConsentValues);
},

Expand Down
4 changes: 2 additions & 2 deletions src/containers/AccountModal/forms/Registration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useQuery, useQueryClient } from 'react-query';

import useForm, { UseFormOnSubmitHandler } from '#src/hooks/useForm';
import RegistrationForm from '#components/RegistrationForm/RegistrationForm';
import { extractConsentValues, checkConsentsFromValues, noEmptyStringEntries, formatCrfEntries } from '#src/utils/collection';
import { extractConsentValues, checkConsentsFromValues, isNotEmptyStringEntry, formatCrfEntry } from '#src/utils/collection';
import { addQueryParam } from '#src/utils/location';
import type { RegistrationFormData } from '#types/account';
import { getPublisherConsents, register, updateConsents } from '#src/stores/AccountController';
Expand Down Expand Up @@ -57,7 +57,7 @@ const Registration = () => {
return;
}

const cleanConsentValues = Object.fromEntries(Object.entries(consentValues).filter(noEmptyStringEntries).map(formatCrfEntries));
const cleanConsentValues = Object.fromEntries(Object.entries(consentValues).filter(isNotEmptyStringEntry).map(formatCrfEntry));

await register(email, password, cleanConsentValues);

Expand Down
8 changes: 4 additions & 4 deletions src/utils/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ const checkConsentsFromValues = (publisherConsents: Consent[], consents: Record<
return { customerConsents, consentsErrors };
};

const noEmptyStringEntries = <T>([, value]: [string, T]) => value !== '';
const isNotEmptyStringEntry = <T>([, value]: [string, T]) => value !== '';

const formatCrfEntries = <T>([name, value]: [string, T], _: number, collection: [string, T][]) => {
const formatCrfEntry = <T>([name, value]: [string, T], _: number, collection: [string, T][]) => {
const val = (() => {
if (name === 'us_state') {
if (Object.fromEntries(collection).country === 'us') {
Expand Down Expand Up @@ -201,6 +201,6 @@ export {
deepCopy,
parseAspectRatio,
parseTilesDelta,
noEmptyStringEntries,
formatCrfEntries,
isNotEmptyStringEntry,
formatCrfEntry,
};

0 comments on commit ad20660

Please sign in to comment.