* add org to create workflow button * add save button for testing in dev mode * add select all to multi select dropdown * fix select all * pass isOrg to WorkflowDetailsPage * add checkbox to apply to all including future * fix count text on select * WIP schema * shows teams in dropdown * add team option to UI * [WIP] refactor for update handler * filter out "all" from activeOn * fix type error * create more helper functions * create reusable function for scheduling all booking reminders * finish update workflows for orgs (without testing) * fix isAuthorized check for orgs * fix getting newActiveOn * move all helper functions to util file * more code clean up * fix deleting reminders for org workflows * fix adding and editing steps * update form data when workflow is saved * code clean up * fixing creating/deleting reminders when user is member of several teams * fix setting activeOn for teams in useffect * add on delete cascade * make multiSelectSchenbox searchable * set activeOn correctly when checkbox true * WIP * fix type errors in MultiSelectCheckboxes * implemented scheduling org-wide workfow notifications (not yet tested) * fix type errors * type error * add missing changes from merge conflict * remote not needed include statement * fix type errors * code clean up + some todo comments * support org workflows for cancelled workflows * delete reminders from removed members * remove reminders if isActiveOnAll is turned off * fix unti test and type error * code clean up * create basis for testing to book org team event * create org workflow with active team * fix getting active org workflows on team + test setup * fix creating workflow step for tests * fix first org test * add test for user event type with org workflow active * use deleteAllWorkflowReminders everywhere * add test for deleteRemindersFromRemovedActiveOn * fix type errors * make all tests pass * fix type error * fix getSchedule test * code clean up * add missing import * fix type error * fix tests * code clean up * fix imports * update reminders when trigger was changed * check for teamId before userId in reminderScheduler * move getOrgIdFromMemberOrTeamId to different folder * code clean up * fix tests * test setup for scheduleBookingReminders * fix typo * add tests for scheduleBookingReminders * fix prisma default import * fix workflowStep type * add scheduleBookingReminders test for sms * return dummy sid for scheduleSMS testMode * clean up + fixes * add lost changes from merge * get teamId and userId from incoming evt object * removing not needed select * add org support for scheduleMandatory email reminder * add other teams to dropdown * move getAllWorkflows to seperate file and call it in parent function * include org wide workflows in createNewSeat * some fixes + code clean up * add new team to select text count when including future teams is checked * fix upsert and remove sms reminder field * correctly update activeOn if 'including future ...' is enabled * list active Org workflows in event workflows settings * fix sms reminder field in all handlers * add helper function to check if step was edited * fix active on badge on workflow * fix type error * fix double reminders * add teamId: null for userWorkflow query * fix activeOnAll with managed event types * add missing teamId in getAllWorkflows * add a dafaut to prisma param * fix managed event types on select all user workflows * code clean up * better variable name * small fixes in update handler * fix test name to match function name * add info badge * fix workflow count in event type settings * fix getting bookings from children manged event types * delete reminders when user is not part of any time no more * implement feedback * fix disbale workflow in event type settings * fix remove member * create new function getAllWorkflowsFromEventType * add some removed code * use promise.allSettled when deleting workflow reminders * create new function deleteWorkflowRemindersOfRemovedMember.ts * fix userId param * delete org worklfows when team is disbanded * don't trigger active on all workflow if not part of any team * fix active on count badge * add test for deleteWorkflowRemidnersOfRemovedMember * trigger workflow also if not member of any subteam * fix failing test * remove unused code * use testId for go back button * fixes for managed event types & activateEventTypeHandler * code clean up * don't activate workflow on locked managed event type * fix type error * type error * more type fixes * feedback --------- Co-authored-by: CarinaWolli <wollencarina@gmail.com> Co-authored-by: Hariom Balhara <hariombalhara@gmail.com> Co-authored-by: Keith Williams <keithwillcode@gmail.com> Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com>
144 lines
3.8 KiB
TypeScript
144 lines
3.8 KiB
TypeScript
import type { Dispatch, SetStateAction } from "react";
|
|
import React from "react";
|
|
import type {
|
|
GroupBase,
|
|
OptionProps,
|
|
MultiValueProps,
|
|
MultiValue as MultiValueType,
|
|
SingleValue,
|
|
} from "react-select";
|
|
import { components } from "react-select";
|
|
import type { Props } from "react-select";
|
|
|
|
import { classNames } from "@calcom/lib";
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
|
|
import { Select } from "../select";
|
|
|
|
export type Option = {
|
|
value: string;
|
|
label: string;
|
|
};
|
|
|
|
const InputOption: React.FC<OptionProps<Option, boolean, GroupBase<Option>>> = ({
|
|
isDisabled,
|
|
isFocused,
|
|
isSelected,
|
|
children,
|
|
innerProps,
|
|
...rest
|
|
}) => {
|
|
const props = {
|
|
...innerProps,
|
|
};
|
|
|
|
return (
|
|
<components.Option
|
|
{...rest}
|
|
isDisabled={isDisabled}
|
|
isFocused={isFocused}
|
|
isSelected={isSelected}
|
|
innerProps={props}>
|
|
<input
|
|
type="checkbox"
|
|
className="text-emphasis focus:ring-emphasis dark:text-muted border-default h-4 w-4 rounded ltr:mr-2 rtl:ml-2"
|
|
checked={isSelected}
|
|
readOnly
|
|
/>
|
|
{children}
|
|
</components.Option>
|
|
);
|
|
};
|
|
|
|
type MultiSelectionCheckboxesProps = {
|
|
options: { label: string; value: string }[];
|
|
setSelected: Dispatch<SetStateAction<Option[]>>;
|
|
selected: Option[];
|
|
setValue: (s: Option[]) => unknown;
|
|
countText?: string;
|
|
};
|
|
|
|
const MultiValue = ({
|
|
index,
|
|
getValue,
|
|
countText,
|
|
}: {
|
|
index: number;
|
|
getValue: () => readonly Option[];
|
|
countText: string;
|
|
}) => {
|
|
const { t } = useLocale();
|
|
const count = getValue().filter((option) => option.value !== "all").length;
|
|
return <>{!index && count !== 0 && <div>{t(countText, { count })}</div>}</>;
|
|
};
|
|
|
|
export default function MultiSelectCheckboxes({
|
|
options,
|
|
isLoading,
|
|
selected,
|
|
setSelected,
|
|
setValue,
|
|
className,
|
|
isDisabled,
|
|
countText,
|
|
}: Omit<Props, "options"> & MultiSelectionCheckboxesProps) {
|
|
const additonalComponents = {
|
|
MultiValue: (props: MultiValueProps<Option, boolean, GroupBase<Option>>) => (
|
|
<MultiValue {...props} countText={countText || "selected"} />
|
|
),
|
|
};
|
|
|
|
const allOptions = [{ label: "Select all", value: "all" }, ...options];
|
|
|
|
const allSelected = selected.length === options.length ? allOptions : selected;
|
|
|
|
return (
|
|
<Select
|
|
value={allSelected}
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
onChange={(s: MultiValueType<Option> | SingleValue<Option>, event: any) => {
|
|
const allSelected = [];
|
|
|
|
if (s !== null && Array.isArray(s) && s.length > 0) {
|
|
if (s.find((option) => option.value === "all")) {
|
|
if (event.action === "select-option") {
|
|
allSelected.push(...[{ label: "Select all", value: "all" }, ...options]);
|
|
} else {
|
|
allSelected.push(...s.filter((option) => option.value !== "all"));
|
|
}
|
|
} else {
|
|
if (s.length === options.length) {
|
|
if (s.find((option) => option.value === "all")) {
|
|
allSelected.push(...s.filter((option) => option.value !== "all"));
|
|
} else {
|
|
if (event.action === "select-option") {
|
|
allSelected.push(...[...s, { label: "Select all", value: "all" }]);
|
|
}
|
|
}
|
|
} else {
|
|
allSelected.push(...s);
|
|
}
|
|
}
|
|
}
|
|
|
|
setSelected(allSelected);
|
|
setValue(allSelected);
|
|
}}
|
|
variant="checkbox"
|
|
options={allOptions.length > 1 ? allOptions : []}
|
|
isMulti
|
|
isDisabled={isDisabled}
|
|
className={classNames(className ? className : "w-64 text-sm")}
|
|
isSearchable={true}
|
|
closeMenuOnSelect={false}
|
|
hideSelectedOptions={false}
|
|
isLoading={isLoading}
|
|
data-testid="multi-select-check-boxes"
|
|
components={{
|
|
...additonalComponents,
|
|
Option: InputOption,
|
|
}}
|
|
/>
|
|
);
|
|
}
|