Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
valentin0h committed Oct 10, 2024
1 parent 4110f61 commit cdf7a8a
Showing 1 changed file with 63 additions and 63 deletions.
126 changes: 63 additions & 63 deletions integrations/googleanalytics/src/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,79 +5,79 @@ type GARuntimeEnvironment = RuntimeEnvironment<{}, GASiteInstallationConfigurati
type GARuntimeContext = RuntimeContext<GARuntimeEnvironment>;

type GASiteInstallationConfiguration = {
tracking_id?: string;
tracking_id?: string;
};

type GAState = GASiteInstallationConfiguration;

type GAProps = {
siteInstallation: {
configuration?: GASiteInstallationConfiguration;
};
siteInstallation: {
configuration?: GASiteInstallationConfiguration;
};
};

export type GAAction = { action: 'save.config' };

export const configBlock = createComponent<GAProps, GAState, GAAction, GARuntimeContext>({
componentId: 'config',
initialState: (props) => {
const siteInstallation = props.siteInstallation;
return {
tracking_id: siteInstallation.configuration?.tracking_id ?? '',
};
},
action: async (element, action, context) => {
switch (action.action) {
case 'save.config':
const { api, environment } = context;
const siteInstallation = environment.siteInstallation;
if (!siteInstallation) {
throw Error('No site installation found');
}
componentId: 'config',
initialState: (props) => {
const siteInstallation = props.siteInstallation;
return {
tracking_id: siteInstallation.configuration?.tracking_id ?? '',
};
},
action: async (element, action, context) => {
switch (action.action) {
case 'save.config':
const { api, environment } = context;
const siteInstallation = environment.siteInstallation;
if (!siteInstallation) {
throw Error('No site installation found');
}

const configurationBody = {
...siteInstallation.configuration,
tracking_id: element.state.tracking_id,
};
await api.integrations.updateIntegrationSiteInstallation(
siteInstallation.integration,
siteInstallation.installation,
siteInstallation.site,
{
configuration: {
...configurationBody,
},
},
);
return element;
}
},
render: async () => {
return (
<configuration>
<input
label="Client ID"
hint={<text>The unique identifier of your GA app client.</text>}
element={<textinput state="tracking_id" placeholder="Tracking ID" />}
/>
const configurationBody = {
...siteInstallation.configuration,
tracking_id: element.state.tracking_id,
};
await api.integrations.updateIntegrationSiteInstallation(
siteInstallation.integration,
siteInstallation.installation,
siteInstallation.site,
{
configuration: {
...configurationBody,
},
},
);
return element;
}
},
render: async () => {
return (
<configuration>
<input
label="Client ID"
hint={<text>The unique identifier of your GA app client.</text>}
element={<textinput state="tracking_id" placeholder="Tracking ID" />}
/>

<divider />
<input
label=""
hint=""
element={
<button
style="primary"
disabled={false}
label="Save"
tooltip="Save configuration"
onPress={{
action: 'save.config',
}}
/>
}
/>
</configuration>
);
},
<divider />
<input
label=""
hint=""
element={
<button
style="primary"
disabled={false}
label="Save"
tooltip="Save configuration"
onPress={{
action: 'save.config',
}}
/>
}
/>
</configuration>
);
},
});

0 comments on commit cdf7a8a

Please sign in to comment.