Skip to content

Commit 8ffbc2f

Browse files
cdxkerskeptrunedev
authored andcommitted
feature: make reset button only reset onboarding steps
1 parent 1696811 commit 8ffbc2f

2 files changed

Lines changed: 6 additions & 87 deletions

File tree

clients/trieve-shopify-extension/app/components/DatasetSettings.tsx

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -206,32 +206,6 @@ export const DatasetSettings = ({
206206
</InlineStack>
207207
</BlockStack>
208208
</Card>
209-
<Card>
210-
<BlockStack gap="200">
211-
<Text variant="headingLg" as="h1">
212-
Revenue Tracking Settings
213-
</Text>
214-
215-
<FormLayout>
216-
<TextField
217-
autoComplete="off"
218-
label="Checkout Selector"
219-
helpText="The HTML selector of the checkout button on your shopify store. This is used to track revenue when a user clicks the checkout button."
220-
value={unsavedRevenueTrackingOptions?.checkout_selector || ""}
221-
onChange={(e) => {
222-
setUnsavedRevenueTrackingOptions({
223-
...unsavedRevenueTrackingOptions,
224-
checkout_selector: e,
225-
});
226-
}}
227-
/>
228-
</FormLayout>
229-
230-
<InlineStack align="end">
231-
<Button onClick={onRevenueTrackingSettingsSave}>Save</Button>
232-
</InlineStack>
233-
</BlockStack>
234-
</Card>
235209
<Card>
236210
<BlockStack gap="200">
237211
<Text variant="headingLg" as="h1">

clients/trieve-shopify-extension/app/components/ResetSettings.tsx

Lines changed: 6 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
import { Button, Card, Text } from "@shopify/polaris";
22
import { useMutation } from "@tanstack/react-query";
3+
import { setMetafield } from "app/loaders";
34
import { useClientAdminApi } from "app/loaders/clientLoader";
4-
import {
5-
AppMetafieldsQuery,
6-
deleteMetafields,
7-
getPdpMetafields,
8-
MetafieldIdentifierInput,
9-
} from "app/utils/productMetafields";
5+
import { ONBOARD_STEP_META_FIELD } from "app/queries/onboarding";
6+
import { onboardingSteps } from "app/utils/onboarding";
107

118
export const ResetSettings = () => {
129
const adminApi = useClientAdminApi();
@@ -16,69 +13,17 @@ export const ResetSettings = () => {
1613
console.error("Error clearing app metafields", e);
1714
},
1815
mutationFn: async () => {
19-
const products = await getPdpMetafields(adminApi);
20-
const productsWithTrieveMetafields = products.filter(
21-
(p) => p.metafields.nodes.length > 0,
22-
);
23-
const metafieldsToDelete = productsWithTrieveMetafields.reduce(
24-
(acc, p) => {
25-
const productId = p.id;
26-
return acc.concat(
27-
p.metafields.nodes.map((m) => ({
28-
key: m.key,
29-
ownerId: productId,
30-
namespace: m.namespace,
31-
})),
32-
);
33-
},
34-
[] as MetafieldIdentifierInput[],
35-
);
36-
if (metafieldsToDelete.length !== 0) {
37-
await deleteMetafields(adminApi, metafieldsToDelete);
38-
} else {
39-
console.log("No metafields to delete");
40-
}
41-
42-
const appInstallMetafields = await adminApi<AppMetafieldsQuery>(
43-
`#graphql
44-
{
45-
appInstallation{
46-
id
47-
metafields (first: 250, namespace: "trieve"){
48-
nodes {
49-
key
50-
value
51-
}
52-
}
53-
}
54-
}
55-
`,
56-
);
57-
58-
if (appInstallMetafields.error) {
59-
throw new Error("Failed to get app metafields", {
60-
cause: appInstallMetafields.error,
61-
});
62-
}
63-
64-
const appMetafieldsToDelete =
65-
appInstallMetafields.data.appInstallation.metafields.nodes.map((m) => ({
66-
key: m.key,
67-
ownerId: appInstallMetafields.data.appInstallation.id,
68-
namespace: "trieve",
69-
})) as MetafieldIdentifierInput[];
70-
71-
await deleteMetafields(adminApi, appMetafieldsToDelete);
16+
setMetafield(adminApi, ONBOARD_STEP_META_FIELD, onboardingSteps[0].id);
7217
},
7318
});
7419

7520
return (
7621
<Card>
7722
<Text variant="headingLg" as="h1">
78-
Reset Widgets and Onboarding
23+
Reset Onboarding
7924
</Text>
8025
<Text variant="bodyMd" as="p">
81-
Clears all app metafields, onboarding data, and widget configuration.
26+
This will reset your onboarding progress so you can view the steps again.
8227
</Text>
8328
<div className="h-3"></div>
8429
<div className="flex items-center gap-4">

0 commit comments

Comments
 (0)