This reverts commit 285d1ec4c9.
This commit is contained in:
1 parent
8ee27d3997
commit
92845d3adc
8 files changed
+139
-148
No files matched your search
@@ -0,0 +1,90 @@
|
||||
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>
|
||||
);
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
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>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user