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 <55134778+sean-brydon@users.noreply.github.com>
Co-authored-by: alannnc <alannnc@gmail.com>
This commit is contained in:
Udit Takkar 2022-11-24 00:48:00 +05:30 committed by GitHub
parent b31b8cc6df
commit 4086a666ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 2 deletions

View File

@ -186,6 +186,7 @@ export const EventTypeList = ({ group, groupIndex, readOnly, types }: EventTypeL
length: type.length,
type: type.schedulingType,
teamId: group.teamId,
locations: encodeURIComponent(JSON.stringify(type.locations)),
};
if (!group.teamId) {
delete query.teamId;

View File

@ -9,8 +9,9 @@ export const createEventTypeInput = _EventTypeModel
teamId: true,
schedulingType: true,
hidden: true,
locations: true
})
.partial({ hidden: true })
.partial({ hidden: true, locations: true })
.refine((data) => (data.teamId ? data.teamId && data.schedulingType : true), {
path: ["schedulingType"],
message: "You must select a scheduling type for team events",

View File

@ -156,6 +156,7 @@ export const eventTypesRouter = router({
// Position is required by lodash to sort on it. Don't remove it, TS won't complain but it would silently break reordering
position: true,
hashedLink: true,
locations: true,
destinationCalendar: true,
team: {
select: {

View File

@ -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])}