Skip to content

Commit

Permalink
fix: make terms field dynamic
Browse files Browse the repository at this point in the history
  • Loading branch information
mirovladimitrovski committed Oct 20, 2023
1 parent d4226c2 commit 8931596
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
4 changes: 3 additions & 1 deletion public/locales/en/account.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@
"weak": "Weak"
},
"sign_up": "Sign up",
"terms_consent": "I accept the {{termsUrl}} of JW Player.",
"terms_consent": "I accept the {{termsLink}}.",
"terms_consent_jwplayer": "I accept the {{termsLink}} of JW Player.",
"terms_and_conditions": "Terms and Conditions",
"user_exists": "There is already a user with this email address",
"view_password": "View password"
},
Expand Down
4 changes: 3 additions & 1 deletion public/locales/es/account.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@
"weak": "Débil"
},
"sign_up": "Registrarse",
"terms_consent": "Acepto los {{termsUrl}} de JW Player.",
"terms_consent": "Acepto los {{termsLink}}.",
"terms_consent_jwplayer": "Acepto los {{termsLink}} de JW Player.",
"terms_and_conditions": "Términos y condiciones",
"user_exists": "Ya existe un usuario con esta dirección de correo electrónico",
"view_password": "Ver contraseña"
},
Expand Down
16 changes: 10 additions & 6 deletions src/services/inplayer.account.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import InPlayer, { AccountData, Env, FavoritesData, UpdateAccountData, WatchHistory } from '@inplayer-org/inplayer.js';
import InPlayer, { AccountData, Env, FavoritesData, UpdateAccountData, WatchHistory, type RegisterField } from '@inplayer-org/inplayer.js';
import i18next from 'i18next';

import { formatConsentsToRegisterFields } from '#src/utils/collection';
Expand Down Expand Up @@ -39,6 +39,8 @@ enum InPlayerEnv {
Daily = 'daily',
}

const JW_TERMS_URL = 'https://inplayer.com/legal/terms';

export const initialize = async (config: Config, _logoutFn: () => Promise<void>) => {
const env: string = config.integrations?.jwp?.useSandbox ? InPlayerEnv.Development : InPlayerEnv.Production;
InPlayer.setConfig(env as Env);
Expand Down Expand Up @@ -162,9 +164,11 @@ export const getPublisherConsents: GetPublisherConsents = async (config) => {
const { jwp } = config.integrations;
const { data } = await InPlayer.Account.getRegisterFields(jwp?.clientId || '');

const terms = data?.collection.find(({ name }) => name === 'terms');

const result = data?.collection
// we exclude these fields because we already have them by default
.filter((field) => !['email_confirmation', 'first_name', 'surname'].includes(field.name))
.filter((field) => !['email_confirmation', 'first_name', 'surname'].includes(field.name) && ![terms].includes(field))
.map(
(field): Consent => ({
type: field.type as CustomRegisterFieldVariant,
Expand All @@ -186,7 +190,7 @@ export const getPublisherConsents: GetPublisherConsents = async (config) => {
}),
);

const consents = [getTermsConsent(), ...result];
const consents = terms ? [getTermsConsent(terms), ...result] : result;

return { consents };
} catch {
Expand Down Expand Up @@ -480,15 +484,15 @@ function formatAuth(auth: InPlayerAuthData): AuthData {
};
}

function getTermsConsent(): Consent {
const termsUrl = '<a href="https://inplayer.com/legal/terms" target="_blank">Terms and Conditions</a>';
function getTermsConsent({ label: termsUrl }: RegisterField): Consent {
const termsLink = `<a href="${termsUrl || JW_TERMS_URL}" target="_blank">${i18next.t('account:registration.terms_and_conditions')}</a>`;

return {
type: 'checkbox',
isCustomRegisterField: true,
required: true,
name: 'terms',
label: i18next.t('account:registration.terms_consent', { termsUrl }),
label: i18next.t(`account:registration.${termsUrl ? 'terms_consent' : 'terms_consent_jwplayer'}`, { termsLink }),
enabledByDefault: false,
placeholder: '',
options: {},
Expand Down

0 comments on commit 8931596

Please sign in to comment.