From a776c72d48b37ff89a8db51ac39510e092837b1c Mon Sep 17 00:00:00 2001 From: Carina Wollendorfer <30310907+CarinaWolli@users.noreply.github.com> Date: Sat, 10 Feb 2024 14:28:59 -0500 Subject: [PATCH] fix: improvements for variables in routing-from routes (#13624) * add variable description * type fixes * type fixes --------- Co-authored-by: CarinaWolli --- apps/web/public/static/locales/en/common.json | 2 + .../pages/route-builder/[...appPages].tsx | 40 +++++++++++++++---- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/apps/web/public/static/locales/en/common.json b/apps/web/public/static/locales/en/common.json index d5b18f2d55..cee336d2b8 100644 --- a/apps/web/public/static/locales/en/common.json +++ b/apps/web/public/static/locales/en/common.json @@ -2258,6 +2258,8 @@ "set_priority": "Set Priority", "priority_for_user": "Priority for {{userName}}", "change_priority": "change priority", + "field_identifiers_as_variables": "Use field identifiers as variables for your custom event redirect", + "field_identifiers_as_variables_with_example": "Use field identifiers as variables for your custom event redirect (e.g. {{variable}})", "account_already_linked": "Account is already linked", "ADD_NEW_STRINGS_ABOVE_THIS_LINE_TO_PREVENT_MERGE_CONFLICTS": "↑↑↑↑↑↑↑↑↑↑↑↑↑ Add your new strings above here ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑" } diff --git a/packages/app-store/routing-forms/pages/route-builder/[...appPages].tsx b/packages/app-store/routing-forms/pages/route-builder/[...appPages].tsx index a65df14b36..949a088d3c 100644 --- a/packages/app-store/routing-forms/pages/route-builder/[...appPages].tsx +++ b/packages/app-store/routing-forms/pages/route-builder/[...appPages].tsx @@ -80,6 +80,7 @@ const Route = ({ moveDown, appUrl, disabled = false, + fieldIdentifiers, }: { form: inferSSRProps["form"]; route: Route; @@ -87,6 +88,7 @@ const Route = ({ setRoute: (id: string, route: Partial) => void; config: QueryBuilderUpdatedConfig; setRoutes: React.Dispatch>; + fieldIdentifiers: string[]; moveUp?: { fn: () => void; check: () => boolean } | null; moveDown?: { fn: () => void; check: () => boolean } | null; appUrl: string; @@ -136,8 +138,8 @@ const Route = ({ ? eventOptions[0].value.substring(0, eventOptions[0].value.lastIndexOf("/") + 1) : ""; - const [customEventTypeSlug, setCustomEventTypeSlug] = useState( - !isRouter(route) ? route.action.value.split("/").pop() : "" + const [customEventTypeSlug, setCustomEventTypeSlug] = useState( + !isRouter(route) ? route.action.value.split("/").pop() ?? "" : "" ); const onChange = (route: Route, immutableTree: ImmutableTree, config: QueryBuilderUpdatedConfig) => { @@ -271,7 +273,7 @@ const Route = ({ isDisabled={disabled} options={ eventOptions.length !== 0 - ? eventOptions.concat({ label: t("Custom"), value: "custom" }) + ? [{ label: t("custom"), value: "custom" }].concat(eventOptions) : [] } onChange={(option) => { @@ -280,6 +282,7 @@ const Route = ({ } if (option.value !== "custom") { setRoute(route.id, { action: { ...route.action, value: option.value } }); + setCustomEventTypeSlug(""); } else { setRoute(route.id, { action: { ...route.action, value: "custom" } }); setCustomEventTypeSlug(""); @@ -287,7 +290,10 @@ const Route = ({ }} value={ eventOptions.length !== 0 && route.action.value !== "" - ? eventOptions.find((eventOption) => eventOption.value === route.action.value) || { + ? eventOptions.find( + (eventOption) => + eventOption.value === route.action.value && !customEventTypeSlug.length + ) || { label: t("custom"), value: "custom", } @@ -295,8 +301,10 @@ const Route = ({ } /> {eventOptions.length !== 0 && - route.action.value !== "" && - !eventOptions.find((eventOption) => eventOption.value === route.action.value) && ( + route.action.value !== "" && + (!eventOptions.find((eventOption) => eventOption.value === route.action.value) || + customEventTypeSlug.length) ? ( + <> - )} +
+

+ {fieldIdentifiers.length + ? t("field_identifiers_as_variables_with_example", { + variable: `{${fieldIdentifiers[0]}}`, + }) + : t("field_identifiers_as_variables")} +

+
+ + ) : ( + <> + )} ) ) : null} @@ -504,6 +524,10 @@ const Routes = ({ hookForm.setValue("routes", routesToSave); + const fields = hookForm.getValues("fields"); + + const fieldIdentifiers = fields ? fields.map((field) => field.identifier ?? field.label) : []; + return (
@@ -515,6 +539,7 @@ const Routes = ({ key={route.id} config={config} route={route} + fieldIdentifiers={fieldIdentifiers} moveUp={{ check: () => key !== 0, fn: () => { @@ -587,6 +612,7 @@ const Routes = ({ setRoute={setRoute} setRoutes={setRoutes} appUrl={appUrl} + fieldIdentifiers={fieldIdentifiers} />