Skip to content

Commit

Permalink
CYS - Core: install font when user clicks opt-in
Browse files Browse the repository at this point in the history
  • Loading branch information
gigitux committed Mar 14, 2024
1 parent 59635fb commit 4439716
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 37 deletions.
Expand Up @@ -67,7 +67,7 @@ export const SidebarNavigationScreenTypography = () => {
upgradeNotice = '';
}

const OptIn = () => {
const optIn = () => {
recordEvent(
'customize_your_store_assembler_hub_opt_in_usage_tracking'
);
Expand Down Expand Up @@ -201,18 +201,8 @@ export const SidebarNavigationScreenTypography = () => {
</Button>
<Button
onClick={ async () => {
await dispatch(
OPTIONS_STORE_NAME
).updateOptions( {
woocommerce_allow_tracking:
OptInDataSharing
? 'yes'
: 'no',
} );

OptIn();
closeModal();
window.location.href = `${ ADMIN_URL }admin.php?page=wc-admin&path=%2Fcustomize-store%2Fassembler-hub`;
optIn();
window.location.href = `${ ADMIN_URL }admin.php?page=wc-admin&path=%2Fcustomize-store/design/install-fonts`;
} }
variant="primary"
disabled={ ! OptInDataSharing }
Expand Down
Expand Up @@ -205,11 +205,23 @@ const updateGlobalStylesWithDefaultValues = async (
);
};

export const enableTracking = async () => {
try {
await dispatch( OPTIONS_STORE_NAME ).updateOptions( {
woocommerce_allow_tracking: 'yes',
} );
window.wcTracks.isEnabled = true;
} catch ( error ) {
throw error;
}
};

export const services = {
assembleSite,
browserPopstateHandler,
installAndActivateTheme,
createProducts,
installFontFamilies,
updateGlobalStylesWithDefaultValues,
enableTracking,
};
Expand Up @@ -29,6 +29,47 @@ export const hasStepInUrl = (
);
};

export const hasInstallFontsInUrl = () => {
const { path = '' } = getQuery() as { path: string };
const pathFragments = path.split( '/' );
debugger;
return (
pathFragments[ 2 ] === 'design' &&
pathFragments[ 3 ] === 'install-fonts'
);
};

const installFontFamiliesState = {
initial: 'checkFontLibrary',
states: {
checkFontLibrary: {
always: [
{
cond: {
type: 'isFontLibraryAvailable',
},
target: 'pending',
},
{ target: 'success' },
],
},
pending: {
invoke: {
src: 'installFontFamilies',
onDone: {
target: 'success',
},
onError: {
actions: 'redirectToIntroWithError',
},
},
},
success: {
type: 'final',
},
},
};

export type DesignWithoutAIStateMachineEvents =
| { type: 'EXTERNAL_URL_UPDATE' }
| { type: 'NO_AI_FLOW_ERROR'; payload: { hasError: boolean } };
Expand Down Expand Up @@ -62,6 +103,12 @@ export const designWithNoAiStateMachineDefinition = createMachine(
states: {
navigate: {
always: [
{
cond: {
type: 'hasInstallFontsInUrl',
},
target: 'installFontFamilies',
},
{
cond: {
type: 'hasStepInUrl',
Expand All @@ -71,6 +118,32 @@ export const designWithNoAiStateMachineDefinition = createMachine(
},
],
},
installFontFamilies: {
meta: {
component: ApiCallLoader,
},
initial: 'enableTracking',
states: {
enableTracking: {
invoke: {
src: 'enableTracking',
onDone: {
target: 'checkFontLibrary',
},
},
},
checkFontLibrary:
installFontFamiliesState.states.checkFontLibrary,
pending: installFontFamiliesState.states.pending,
success: {
meta: {
component: AssembleHubLoader,
},
entry: [ 'redirectToAssemblerHub' ],
type: 'final',
},
},
},
preAssembleSite: {
initial: 'preApiCallLoader',
id: 'preAssembleSite',
Expand Down Expand Up @@ -161,31 +234,14 @@ export const designWithNoAiStateMachineDefinition = createMachine(
},
},
installFontFamilies: {
initial: 'checkFontLibrary',
...installFontFamiliesState,
states: {
checkFontLibrary: {
always: [
{
cond: {
type: 'isFontLibraryAvailable',
},
target: 'pending',
},
{ target: 'success' },
],
},
pending: {
invoke: {
src: 'installFontFamilies',
onDone: {
target: 'success',
},
onError: {
actions:
'redirectToIntroWithError',
},
},
},
...installFontFamiliesState.states,
checkFontLibrary:
installFontFamiliesState.states
.checkFontLibrary,
pending:
installFontFamiliesState.states.pending,
success: {
type: 'final',
},
Expand Down Expand Up @@ -213,6 +269,7 @@ export const designWithNoAiStateMachineDefinition = createMachine(
services,
guards: {
hasStepInUrl,
hasInstallFontsInUrl,
isFontLibraryAvailable,
},
}
Expand Down

0 comments on commit 4439716

Please sign in to comment.