|
1 | 1 | import { templateByName } from "api/queries/templates";
|
2 | 2 | import { ErrorAlert } from "components/Alert/ErrorAlert";
|
3 | 3 | import { Loader } from "components/Loader/Loader";
|
4 |
| -import { useDashboard } from "modules/dashboard/useDashboard"; |
5 |
| -import { ExperimentalFormContext } from "pages/CreateWorkspacePage/ExperimentalFormContext"; |
6 | 4 | import type { FC } from "react";
|
7 | 5 | import { useQuery } from "react-query";
|
8 | 6 | import { useParams } from "react-router-dom";
|
9 | 7 | import TemplateEmbedPage from "./TemplateEmbedPage";
|
10 | 8 | import TemplateEmbedPageExperimental from "./TemplateEmbedPageExperimental";
|
11 | 9 |
|
12 | 10 | const TemplateEmbedExperimentRouter: FC = () => {
|
13 |
| - const { experiments } = useDashboard(); |
14 |
| - const dynamicParametersEnabled = experiments.includes("dynamic-parameters"); |
15 |
| - |
16 | 11 | const { organization: organizationName = "default", template: templateName } =
|
17 | 12 | useParams() as { organization?: string; template: string };
|
18 | 13 | const templateQuery = useQuery(
|
19 |
| - dynamicParametersEnabled |
20 |
| - ? templateByName(organizationName, templateName) |
21 |
| - : { enabled: false }, |
22 |
| - ); |
23 |
| - |
24 |
| - const optOutQuery = useQuery( |
25 |
| - templateQuery.data |
26 |
| - ? { |
27 |
| - queryKey: [ |
28 |
| - organizationName, |
29 |
| - "template", |
30 |
| - templateQuery.data.id, |
31 |
| - "optOut", |
32 |
| - ], |
33 |
| - queryFn: () => { |
34 |
| - const templateId = templateQuery.data.id; |
35 |
| - const localStorageKey = optOutKey(templateId); |
36 |
| - const storedOptOutString = localStorage.getItem(localStorageKey); |
37 |
| - |
38 |
| - let optOutResult: boolean; |
39 |
| - |
40 |
| - if (storedOptOutString !== null) { |
41 |
| - optOutResult = storedOptOutString === "true"; |
42 |
| - } else { |
43 |
| - optOutResult = Boolean( |
44 |
| - templateQuery.data.use_classic_parameter_flow, |
45 |
| - ); |
46 |
| - } |
47 |
| - |
48 |
| - return { |
49 |
| - templateId: templateId, |
50 |
| - optedOut: optOutResult, |
51 |
| - }; |
52 |
| - }, |
53 |
| - } |
54 |
| - : { enabled: false }, |
| 14 | + templateByName(organizationName, templateName), |
55 | 15 | );
|
56 | 16 |
|
57 |
| - if (dynamicParametersEnabled) { |
58 |
| - if (optOutQuery.isLoading) { |
59 |
| - return <Loader />; |
60 |
| - } |
61 |
| - if (!optOutQuery.data) { |
62 |
| - return <ErrorAlert error={optOutQuery.error} />; |
63 |
| - } |
64 |
| - |
65 |
| - const toggleOptedOut = () => { |
66 |
| - const key = optOutKey(optOutQuery.data.templateId); |
67 |
| - const storedValue = localStorage.getItem(key); |
68 |
| - |
69 |
| - const current = storedValue |
70 |
| - ? storedValue === "true" |
71 |
| - : Boolean(templateQuery.data?.use_classic_parameter_flow); |
72 |
| - |
73 |
| - localStorage.setItem(key, (!current).toString()); |
74 |
| - optOutQuery.refetch(); |
75 |
| - }; |
76 |
| - return ( |
77 |
| - <ExperimentalFormContext.Provider value={{ toggleOptedOut }}> |
78 |
| - {optOutQuery.data.optedOut ? ( |
79 |
| - <TemplateEmbedPage /> |
80 |
| - ) : ( |
81 |
| - <TemplateEmbedPageExperimental /> |
82 |
| - )} |
83 |
| - </ExperimentalFormContext.Provider> |
84 |
| - ); |
| 17 | + if (templateQuery.isError) { |
| 18 | + return <ErrorAlert error={templateQuery.error} />; |
| 19 | + } |
| 20 | + if (!templateQuery.data) { |
| 21 | + return <Loader />; |
85 | 22 | }
|
86 | 23 |
|
87 |
| - return <TemplateEmbedPage />; |
| 24 | + return ( |
| 25 | + <> |
| 26 | + {templateQuery.data?.use_classic_parameter_flow ? ( |
| 27 | + <TemplateEmbedPage /> |
| 28 | + ) : ( |
| 29 | + <TemplateEmbedPageExperimental /> |
| 30 | + )} |
| 31 | + </> |
| 32 | + ); |
88 | 33 | };
|
89 | 34 |
|
90 | 35 | export default TemplateEmbedExperimentRouter;
|
91 |
| - |
92 |
| -const optOutKey = (id: string) => `parameters.${id}.optOut`; |
0 commit comments