fix: add location query variable (#5540)

* fix: add location query variable

* chore: remove logs

* fix: remove required location

* fix: make locations option

* fix: get location

* Update packages/prisma/zod/custom/eventtype.ts

Co-authored-by: sean-brydon <[email protected]>
Co-authored-by: alannnc <[email protected]>
This commit is contained in:
authored and GitHub committed 2022-11-23 12:18:00 -07:00
1 parent b31b8cc6df
commit 4086a666ae
4 files changed
+29 -2

No files matched your search

@@ -52,6 +52,15 @@ interface CreateEventTypeBtnProps {
options: EventTypeParent[];
}
const isValidJSONString = (str: string) => {
try {
JSON.parse(str);
} catch (e) {
return false;
}
return true;
};
export default function CreateEventTypeButton(props: CreateEventTypeBtnProps) {
const { t } = useLocale();
const router = useRouter();
@@ -82,7 +91,13 @@ export default function CreateEventTypeButton(props: CreateEventTypeBtnProps) {
? router.query.description
: "";
const slug: string = typeof router.query.slug === "string" && router.query.slug ? router.query.slug : "";
const locations =
typeof router.query.locations === "string" &&
isValidJSONString(decodeURIComponent(router.query.locations))
? JSON.parse(decodeURIComponent(router.query.locations))
: [];
setValue("locations", locations);
setValue("title", title);
setValue("length", length);
setValue("description", description);
@@ -137,7 +152,16 @@ export default function CreateEventTypeButton(props: CreateEventTypeBtnProps) {
return (
<Dialog
name="new-eventtype"
clearQueryParamsOnClose={["eventPage", "teamId", "type", "description", "title", "length", "slug"]}>
clearQueryParamsOnClose={[
"eventPage",
"teamId",
"type",
"description",
"title",
"length",
"slug",
"locations",
]}>
{!hasTeams || props.isIndividualTeam ? (
<Button
onClick={() => openModal(props.options[0])}