fix: Autodetection of time zone only updated default time zone (#15392)

* fix: Autodetection of time zone only updated default time zone

* fix: description text

---------

Co-authored-by: sean-brydon <[email protected]>
This commit is contained in:
Amit Sharmaandsean-brydon authored and GitHub committed 2024-06-28 10:12:33 +01:00
1 parent c458b297ae
commit 285d1ec4c9
8 files changed
+148 -139

No files matched your search

@@ -1,90 +0,0 @@
import { zodResolver } from "@hookform/resolvers/zod";
import { useForm } from "react-hook-form";
import { z } from "zod";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { trpc } from "@calcom/trpc/react";
import { Dialog, DialogContent, Form, DialogFooter, DialogClose, Button, CheckboxField } from "@calcom/ui";
export const BulkUpdateEventSchema = z.object({
eventTypeIds: z.array(z.number()),
});
export function BulkEditDefaultForEventsModal(props: {
open: boolean;
setOpen: (open: boolean) => void;
bulkUpdateFunction: ({ eventTypeIds }: { eventTypeIds: number[] }) => void;
isPending: boolean;
}) {
const { t } = useLocale();
const utils = trpc.useUtils();
const { data, isFetching } = trpc.viewer.eventTypes.bulkEventFetch.useQuery();
const form = useForm({
resolver: zodResolver(BulkUpdateEventSchema),
defaultValues: {
eventTypeIds: data?.eventTypes.map((e) => e.id) ?? [],
},
});
const eventTypesSelected = form.watch("eventTypeIds");
if (isFetching || !open || !data?.eventTypes) return null;
return (
<Dialog name="Bulk Default Location Update" open={props.open} onOpenChange={props.setOpen}>
<DialogContent
type="creation"
title={t("default_conferencing_bulk_title")}
description={t("default_conferencing_bulk_description")}
enableOverflow>
<Form
form={form}
handleSubmit={(values) => {
props.bulkUpdateFunction(values);
}}>
<div className="flex flex-col space-y-2">
{data.eventTypes.length > 0 && (
<div className="flex items-center space-x-2 rounded-md px-3 pb-2.5 pt-1">
<CheckboxField
description={t("select_all")}
descriptionAsLabel
onChange={(e) => {
form.setValue("eventTypeIds", e.target.checked ? data.eventTypes.map((e) => e.id) : []);
}}
checked={eventTypesSelected.length === data.eventTypes.length}
/>
</div>
)}
{data.eventTypes.map((eventType) => (
<div key={eventType.id} className="bg-muted flex items-center space-x-2 rounded-md px-3 py-2.5">
<CheckboxField
description={eventType.title}
descriptionAsLabel
checked={eventTypesSelected.includes(eventType.id)}
onChange={(e) => {
form.setValue(
"eventTypeIds",
e.target.checked
? [...eventTypesSelected, eventType.id]
: eventTypesSelected.filter((id) => id !== eventType.id)
);
}}
/>
</div>
))}
</div>
<DialogFooter showDivider className="mt-10">
<DialogClose
onClick={() => {
utils.viewer.getUsersDefaultConferencingApp.invalidate();
}}
/>
<Button type="submit" color="primary" loading={props.isPending}>
{t("update")}
</Button>
</DialogFooter>
</Form>
</DialogContent>
</Dialog>
);
}
@@ -0,0 +1,63 @@
import type { Dispatch, SetStateAction } from "react";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { Dialog, DialogContent, DialogFooter, DialogClose, Button, CheckboxField } from "@calcom/ui";
export function BulkEditDefaultModal(props: {
open: boolean;
setOpen: (open: boolean) => void;
ids: number[];
setIds: Dispatch<SetStateAction<number[]>>;
isPending: boolean;
data?: {
id: number;
title: string;
default?: boolean;
}[];
title: string;
description: string;
handleSubmit: () => void;
}) {
const { title, description, handleSubmit, data, ids, setIds, open } = props;
const { t } = useLocale();
if (!open || !data || !ids) return null;
return (
<Dialog name="Bulk Default Update" open={props.open} onOpenChange={props.setOpen}>
<DialogContent type="creation" title={title} description={description} enableOverflow>
<div className="flex flex-col space-y-2">
{data.length > 0 && (
<div className="flex items-center space-x-2 rounded-md px-3 pb-2.5 pt-1">
<CheckboxField
description={t("select_all")}
descriptionAsLabel
onChange={(e) => {
setIds(e.target.checked ? data.map((e) => e.id) : []);
}}
checked={ids.length === data.length}
/>
</div>
)}
{data.map((item) => (
<div key={item.id} className="bg-muted flex items-center space-x-2 rounded-md px-3 py-2.5">
<CheckboxField
description={item.title}
descriptionAsLabel
checked={ids.includes(item.id)}
onChange={(e) => {
setIds(e.target.checked ? [...ids, item.id] : ids.filter((id) => id !== item.id));
}}
/>
</div>
))}
</div>
<DialogFooter showDivider className="mt-10">
<DialogClose />
<Button type="submit" color="primary" loading={props.isPending} onClick={handleSubmit}>
{t("update")}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
}