* Initial incomplete (but mostly functional) push of date override functions * Fixed date shifting on load * Bring back minDate (automatically disable all dates before current date) * Fix type error * Supply working hours to render available dates * Converted to SSR * moving defaultValues to the backend * Improv. as filter can be achieved within the reduce Co-authored-by: Omar López <zomars@me.com> * Double inversion -> single, as it is an early return * uniq() exit - not needed anymore * Typefixes * It's overriding dates :D * Fixed duplication DateOverrides in list * Implemented changing the month * Make dateOverrides an optional param * Fixed test (which requires dateOverrides due to auto-typing) * Prevent a full update on set as default from list view * Added some extra keys to keep ts happy * Only allow a single date override per date * Disallow editing excludedDates to the same date * Bring back duplicate key ?.? Co-authored-by: Peer Richelsen <peeroke@gmail.com> Co-authored-by: zomars <zomars@me.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
114 lines
3.4 KiB
TypeScript
114 lines
3.4 KiB
TypeScript
import { MembershipRole } from "@prisma/client";
|
|
import { SyntheticEvent, useMemo, useState } from "react";
|
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
import { trpc } from "@calcom/trpc/react";
|
|
import { Button, Dialog, DialogContent, Select } from "@calcom/ui";
|
|
|
|
type MembershipRoleOption = {
|
|
label: string;
|
|
value: MembershipRole;
|
|
};
|
|
|
|
export default function MemberChangeRoleModal(props: {
|
|
isOpen: boolean;
|
|
currentMember: MembershipRole;
|
|
memberId: number;
|
|
teamId: number;
|
|
initialRole: MembershipRole;
|
|
onExit: () => void;
|
|
}) {
|
|
const { t } = useLocale();
|
|
|
|
const options = useMemo(() => {
|
|
return [
|
|
{
|
|
label: t("member"),
|
|
value: MembershipRole.MEMBER,
|
|
},
|
|
{
|
|
label: t("admin"),
|
|
value: MembershipRole.ADMIN,
|
|
},
|
|
{
|
|
label: t("owner"),
|
|
value: MembershipRole.OWNER,
|
|
},
|
|
].filter(({ value }) => value !== MembershipRole.OWNER || props.currentMember === MembershipRole.OWNER);
|
|
}, [t, props.currentMember]);
|
|
|
|
const [role, setRole] = useState<MembershipRoleOption>(
|
|
options.find((option) => option.value === props.initialRole) || {
|
|
label: t("member"),
|
|
value: MembershipRole.MEMBER,
|
|
}
|
|
);
|
|
const [errorMessage, setErrorMessage] = useState("");
|
|
const utils = trpc.useContext();
|
|
|
|
const changeRoleMutation = trpc.viewer.teams.changeMemberRole.useMutation({
|
|
async onSuccess() {
|
|
await utils.viewer.teams.get.invalidate();
|
|
props.onExit();
|
|
},
|
|
async onError(err) {
|
|
setErrorMessage(err.message);
|
|
},
|
|
});
|
|
|
|
function changeRole(e: SyntheticEvent) {
|
|
e.preventDefault();
|
|
|
|
changeRoleMutation.mutate({
|
|
teamId: props.teamId,
|
|
memberId: props.memberId,
|
|
role: role.value,
|
|
});
|
|
}
|
|
return (
|
|
<Dialog open={props.isOpen} onOpenChange={props.onExit}>
|
|
<DialogContent type="creation">
|
|
<>
|
|
<div className="mb-4 sm:flex sm:items-start">
|
|
<div className="text-center sm:text-left">
|
|
<h3 className="text-lg font-medium leading-6 text-gray-900" id="modal-title">
|
|
{t("change_member_role")}
|
|
</h3>
|
|
</div>
|
|
</div>
|
|
<form onSubmit={changeRole}>
|
|
<div className="mb-4">
|
|
<label className="mb-2 block text-sm font-medium tracking-wide text-gray-700" htmlFor="role">
|
|
{t("role")}
|
|
</label>
|
|
{/*<option value="OWNER">{t("owner")}</option> - needs dialog to confirm change of ownership */}
|
|
<Select
|
|
isSearchable={false}
|
|
options={options}
|
|
value={role}
|
|
onChange={(option) => option && setRole(option)}
|
|
id="role"
|
|
className="mt-1 block w-full rounded-md border-gray-300 text-sm"
|
|
/>
|
|
</div>
|
|
{errorMessage && (
|
|
<p className="text-sm text-red-700">
|
|
<span className="font-bold">Error: </span>
|
|
{errorMessage}
|
|
</p>
|
|
)}
|
|
<div className="mt-5 sm:mt-4 sm:flex sm:flex-row-reverse">
|
|
<Button type="submit" color="primary" className="ltr:ml-2 rtl:mr-2">
|
|
{t("save")}
|
|
</Button>
|
|
<Button type="button" color="secondary" onClick={props.onExit}>
|
|
{t("cancel")}
|
|
</Button>
|
|
</div>
|
|
</form>
|
|
</>
|
|
</DialogContent>
|
|
</Dialog>
|
|
);
|
|
}
|