Skip to content

Commit

Permalink
fix: inplayer: send CRF metadata on register
Browse files Browse the repository at this point in the history
  • Loading branch information
mirovladimitrovski committed Sep 22, 2023
1 parent be3c907 commit 053da25
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/containers/AccountModal/forms/Registration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const Registration = () => {
return;
}

await register(email, password);
await register(email, password, consentValues);

await updateConsents(customerConsents).catch(() => {
// error caught while updating the consents, but continue the registration flow
Expand Down
28 changes: 27 additions & 1 deletion src/services/inplayer.account.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,33 @@ export const login: Login = async ({ config, email, password }) => {
}
};

export const register: Register = async ({ config, email, password }) => {
export const register: Register = async ({ config, email, password, customFields }) => {
try {
const metadata = {
...customFields,
...Object.entries(customFields).reduce((acc, [name, val]) => {
const isBoolean = val === true || val === false;

if (isBoolean) {
if (name === 'terms') {
return { ...acc, [name]: val };
}

return { ...acc, [name]: val === true ? 'on' : 'off' };
}

if (name === 'us_state') {
if (customFields.country === 'us') {
return { ...acc, [name]: val === 'n/a' ? '' : val };
}

return { ...acc, [name]: 'n/a' };
}

return { ...acc, [name]: val };
}, {}),
};

const { data } = await InPlayer.Account.signUpV2({
email,
password,
Expand All @@ -96,6 +121,7 @@ export const register: Register = async ({ config, email, password }) => {
metadata: {
first_name: ' ',
surname: ' ',
...metadata,
},
type: 'consumer',
clientId: config.integrations.jwp?.clientId || '',
Expand Down
4 changes: 2 additions & 2 deletions src/stores/AccountController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,10 @@ export async function logout(logoutOptions: { includeNetworkRequest: boolean } =
});
}

export const register = async (email: string, password: string) => {
export const register = async (email: string, password: string, customFields: Record<string, string | boolean>) => {
await useService(async ({ accountService, accessModel, config }) => {
useAccountStore.setState({ loading: true });
const response = await accountService.register({ config, email, password });
const response = await accountService.register({ config, email, password, customFields });
if (response) {
const { user, customerConsents } = response;
await afterLogin(user, customerConsents, accessModel);
Expand Down
10 changes: 7 additions & 3 deletions types/account.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ export type PayloadWithIPOverride = {
customerIP?: string;
};

export type AuthArgs = {
export type LoginArgs = {
config: Config;
email: string;
password: string;
};

export type RegistrationArgs = LoginArgs & {
customFields: Record<string, string | boolean>;
};

export type AuthResponse = {
auth: AuthData;
user: Customer;
Expand Down Expand Up @@ -360,8 +364,8 @@ export type DeleteAccountPayload = {
password: string;
};

type Login = PromiseRequest<AuthArgs, AuthResponse>;
type Register = PromiseRequest<AuthArgs, AuthResponse>;
type Login = PromiseRequest<LoginArgs, AuthResponse>;
type Register = PromiseRequest<RegistrationArgs, AuthResponse>;
type GetCustomer = EnvironmentServiceRequest<GetCustomerPayload, Customer>;
type UpdateCustomer = EnvironmentServiceRequest<UpdateCustomerArgs, Customer>;
type GetPublisherConsents = PromiseRequest<Config, GetPublisherConsentsResponse>;
Expand Down

0 comments on commit 053da25

Please sign in to comment.