2021-12-09 23:51:30 +00:00
|
|
|
import { UserIcon } from "@heroicons/react/outline";
|
2022-02-07 23:35:26 +00:00
|
|
|
import { InformationCircleIcon } from "@heroicons/react/solid";
|
2021-12-09 23:51:30 +00:00
|
|
|
import { MembershipRole } from "@prisma/client";
|
2021-06-07 15:12:00 +00:00
|
|
|
import { useState } from "react";
|
2021-10-25 13:05:21 +00:00
|
|
|
import React, { SyntheticEvent } from "react";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
2021-10-08 11:43:48 +00:00
|
|
|
import { useLocale } from "@lib/hooks/useLocale";
|
2021-12-09 23:51:30 +00:00
|
|
|
import { TeamWithMembers } from "@lib/queries/teams";
|
|
|
|
import { trpc } from "@lib/trpc";
|
2021-06-05 22:53:33 +00:00
|
|
|
|
2022-02-07 23:35:26 +00:00
|
|
|
import { TextField } from "@components/form/fields";
|
2021-09-22 19:52:38 +00:00
|
|
|
import Button from "@components/ui/Button";
|
|
|
|
|
2021-12-09 23:51:30 +00:00
|
|
|
export default function MemberInvitationModal(props: { team: TeamWithMembers | null; onExit: () => void }) {
|
2021-08-02 20:51:57 +00:00
|
|
|
const [errorMessage, setErrorMessage] = useState("");
|
2021-10-25 13:05:21 +00:00
|
|
|
const { t, i18n } = useLocale();
|
2021-12-09 23:51:30 +00:00
|
|
|
const utils = trpc.useContext();
|
2021-06-07 15:12:00 +00:00
|
|
|
|
2021-12-09 23:51:30 +00:00
|
|
|
const inviteMemberMutation = trpc.useMutation("viewer.teams.inviteMember", {
|
|
|
|
async onSuccess() {
|
|
|
|
await utils.invalidateQueries(["viewer.teams.get"]);
|
|
|
|
props.onExit();
|
|
|
|
},
|
|
|
|
async onError(err) {
|
|
|
|
setErrorMessage(err.message);
|
|
|
|
},
|
|
|
|
});
|
2021-06-07 15:12:00 +00:00
|
|
|
|
2021-12-09 23:51:30 +00:00
|
|
|
function inviteMember(e: SyntheticEvent) {
|
2021-06-05 22:53:33 +00:00
|
|
|
e.preventDefault();
|
2021-12-09 23:51:30 +00:00
|
|
|
if (!props.team) return;
|
2021-06-05 22:53:33 +00:00
|
|
|
|
2021-10-25 13:05:21 +00:00
|
|
|
const target = e.target as typeof e.target & {
|
|
|
|
elements: {
|
2021-12-09 23:51:30 +00:00
|
|
|
role: { value: MembershipRole };
|
2021-10-25 13:05:21 +00:00
|
|
|
inviteUser: { value: string };
|
|
|
|
sendInviteEmail: { checked: boolean };
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-12-09 23:51:30 +00:00
|
|
|
inviteMemberMutation.mutate({
|
|
|
|
teamId: props.team.id,
|
2021-10-25 13:05:21 +00:00
|
|
|
language: i18n.language,
|
|
|
|
role: target.elements["role"].value,
|
|
|
|
usernameOrEmail: target.elements["inviteUser"].value,
|
|
|
|
sendEmailInvitation: target.elements["sendInviteEmail"].checked,
|
2021-12-09 23:51:30 +00:00
|
|
|
});
|
|
|
|
}
|
2021-06-05 22:53:33 +00:00
|
|
|
|
2021-08-02 15:36:28 +00:00
|
|
|
return (
|
|
|
|
<div
|
Cal 262 refactor edit teams according to the design reference (#516)
* refactored settings/team landing page
* changed team edit flow, WIP
* merge conflict fix for teams.tsx
* minor fixes to edit team, WIP
* invite-member and disband team APIs attached inside edit-team page
* added remove-member API in edit-team page, minor fixes
* minor code fix, WIP
* WIP
* add logo, bio, branding to team schema
* bio, logo, branding, slug patch API and minor code fix-- WIP
* fn to Disband team directly from the dropdown menu in settings/teams page, removed debug remnants --WIP
* Pull latest data after an action in settings/teams-edit page
* added slug conflict check at Patch time
* code clean-up
* initial change request fixes --WIP
* prop type fix and add warn button color theme --WIP
* added warn Button to Dialog
* remaining change request fixes
* added noop from react-query
* updated invited team-list design
* prettier fix for api/teams/profile
* removed noop import and added custom noop
* minor Button fix
* requested changes addressed
2021-09-06 13:22:22 +00:00
|
|
|
className="fixed inset-0 z-50 overflow-y-auto"
|
2021-08-02 15:36:28 +00:00
|
|
|
aria-labelledby="modal-title"
|
|
|
|
role="dialog"
|
|
|
|
aria-modal="true">
|
2022-02-09 00:05:13 +00:00
|
|
|
<div className="flex min-h-screen items-end justify-center px-4 pt-4 pb-20 text-center sm:block sm:p-0">
|
2021-08-08 19:21:33 +00:00
|
|
|
<div
|
2022-02-09 00:05:13 +00:00
|
|
|
className="fixed inset-0 z-0 bg-gray-500 bg-opacity-75 transition-opacity"
|
2021-08-08 19:21:33 +00:00
|
|
|
aria-hidden="true"></div>
|
2021-06-05 22:53:33 +00:00
|
|
|
|
2022-02-09 00:05:13 +00:00
|
|
|
<span className="hidden sm:inline-block sm:h-screen sm:align-middle" aria-hidden="true">
|
2021-08-02 15:36:28 +00:00
|
|
|
​
|
|
|
|
</span>
|
2021-06-05 22:53:33 +00:00
|
|
|
|
2022-02-09 00:05:13 +00:00
|
|
|
<div className="inline-block transform rounded-lg bg-white px-4 pt-5 pb-4 text-left align-bottom shadow-xl transition-all sm:my-8 sm:w-full sm:max-w-lg sm:p-6 sm:align-middle">
|
Cal 262 refactor edit teams according to the design reference (#516)
* refactored settings/team landing page
* changed team edit flow, WIP
* merge conflict fix for teams.tsx
* minor fixes to edit team, WIP
* invite-member and disband team APIs attached inside edit-team page
* added remove-member API in edit-team page, minor fixes
* minor code fix, WIP
* WIP
* add logo, bio, branding to team schema
* bio, logo, branding, slug patch API and minor code fix-- WIP
* fn to Disband team directly from the dropdown menu in settings/teams page, removed debug remnants --WIP
* Pull latest data after an action in settings/teams-edit page
* added slug conflict check at Patch time
* code clean-up
* initial change request fixes --WIP
* prop type fix and add warn button color theme --WIP
* added warn Button to Dialog
* remaining change request fixes
* added noop from react-query
* updated invited team-list design
* prettier fix for api/teams/profile
* removed noop import and added custom noop
* minor Button fix
* requested changes addressed
2021-09-06 13:22:22 +00:00
|
|
|
<div className="mb-4 sm:flex sm:items-start">
|
2022-02-09 22:32:31 +00:00
|
|
|
<div className="bg-brand text-brandcontrast mx-auto flex h-12 w-12 flex-shrink-0 items-center justify-center rounded-full bg-opacity-5 sm:mx-0 sm:h-10 sm:w-10">
|
|
|
|
<UserIcon className="text-brandcontrast h-6 w-6" />
|
2021-08-02 15:36:28 +00:00
|
|
|
</div>
|
|
|
|
<div className="mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left">
|
Cal 262 refactor edit teams according to the design reference (#516)
* refactored settings/team landing page
* changed team edit flow, WIP
* merge conflict fix for teams.tsx
* minor fixes to edit team, WIP
* invite-member and disband team APIs attached inside edit-team page
* added remove-member API in edit-team page, minor fixes
* minor code fix, WIP
* WIP
* add logo, bio, branding to team schema
* bio, logo, branding, slug patch API and minor code fix-- WIP
* fn to Disband team directly from the dropdown menu in settings/teams page, removed debug remnants --WIP
* Pull latest data after an action in settings/teams-edit page
* added slug conflict check at Patch time
* code clean-up
* initial change request fixes --WIP
* prop type fix and add warn button color theme --WIP
* added warn Button to Dialog
* remaining change request fixes
* added noop from react-query
* updated invited team-list design
* prettier fix for api/teams/profile
* removed noop import and added custom noop
* minor Button fix
* requested changes addressed
2021-09-06 13:22:22 +00:00
|
|
|
<h3 className="text-lg font-medium leading-6 text-gray-900" id="modal-title">
|
2021-10-08 11:43:48 +00:00
|
|
|
{t("invite_new_member")}
|
2021-08-02 15:36:28 +00:00
|
|
|
</h3>
|
|
|
|
<div>
|
2021-10-08 11:43:48 +00:00
|
|
|
<p className="text-sm text-gray-400">{t("invite_new_team_member")}</p>
|
2021-08-02 15:36:28 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-06-05 22:53:33 +00:00
|
|
|
</div>
|
2021-08-02 15:36:28 +00:00
|
|
|
<form onSubmit={inviteMember}>
|
2022-02-07 23:35:26 +00:00
|
|
|
<div className="space-y-4">
|
|
|
|
<TextField
|
|
|
|
label={t("email_or_username")}
|
|
|
|
id="inviteUser"
|
|
|
|
name="inviteUser"
|
|
|
|
placeholder="email@example.com"
|
|
|
|
required
|
|
|
|
/>
|
|
|
|
<div>
|
2022-02-09 00:05:13 +00:00
|
|
|
<label className="mb-1 block text-sm font-medium tracking-wide text-gray-700" htmlFor="role">
|
2021-10-08 11:43:48 +00:00
|
|
|
{t("role")}
|
2021-08-02 15:36:28 +00:00
|
|
|
</label>
|
|
|
|
<select
|
|
|
|
id="role"
|
2022-02-09 22:32:31 +00:00
|
|
|
className="focus:border-brand mt-1 block w-full rounded-sm border-gray-300 shadow-sm focus:ring-black sm:text-sm">
|
2021-10-08 11:43:48 +00:00
|
|
|
<option value="MEMBER">{t("member")}</option>
|
2021-12-09 23:51:30 +00:00
|
|
|
<option value="ADMIN">{t("admin")}</option>
|
2021-08-02 15:36:28 +00:00
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
<div className="relative flex items-start">
|
2022-02-09 00:05:13 +00:00
|
|
|
<div className="flex h-5 items-center">
|
2021-08-02 15:36:28 +00:00
|
|
|
<input
|
|
|
|
type="checkbox"
|
|
|
|
name="sendInviteEmail"
|
|
|
|
defaultChecked
|
|
|
|
id="sendInviteEmail"
|
2022-02-09 22:32:31 +00:00
|
|
|
className="focus:border-brand rounded-sm border-gray-300 text-black shadow-sm focus:ring-black sm:text-sm"
|
2021-08-02 15:36:28 +00:00
|
|
|
/>
|
|
|
|
</div>
|
2022-02-09 23:10:43 +00:00
|
|
|
<div className="text-sm ltr:ml-2 rtl:mr-2">
|
2021-08-02 15:36:28 +00:00
|
|
|
<label htmlFor="sendInviteEmail" className="font-medium text-gray-700">
|
2021-10-08 11:43:48 +00:00
|
|
|
{t("send_invite_email")}
|
2021-08-02 15:36:28 +00:00
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-02-09 00:05:13 +00:00
|
|
|
<div className="flex flex-row rounded-sm bg-gray-50 px-3 py-2">
|
|
|
|
<InformationCircleIcon className="h-5 w-5 flex-shrink-0 fill-gray-400" aria-hidden="true" />
|
2022-02-07 23:35:26 +00:00
|
|
|
<span className="ml-2 text-sm leading-tight text-gray-500">
|
|
|
|
Note: This will cost an extra seat ($12/m) on your subscription if this invitee does not
|
|
|
|
have a pro account.{" "}
|
|
|
|
<a href="#" className="underline">
|
|
|
|
Learn More
|
|
|
|
</a>
|
|
|
|
</span>
|
|
|
|
</div>
|
2021-08-02 15:36:28 +00:00
|
|
|
</div>
|
|
|
|
{errorMessage && (
|
Cal 262 refactor edit teams according to the design reference (#516)
* refactored settings/team landing page
* changed team edit flow, WIP
* merge conflict fix for teams.tsx
* minor fixes to edit team, WIP
* invite-member and disband team APIs attached inside edit-team page
* added remove-member API in edit-team page, minor fixes
* minor code fix, WIP
* WIP
* add logo, bio, branding to team schema
* bio, logo, branding, slug patch API and minor code fix-- WIP
* fn to Disband team directly from the dropdown menu in settings/teams page, removed debug remnants --WIP
* Pull latest data after an action in settings/teams-edit page
* added slug conflict check at Patch time
* code clean-up
* initial change request fixes --WIP
* prop type fix and add warn button color theme --WIP
* added warn Button to Dialog
* remaining change request fixes
* added noop from react-query
* updated invited team-list design
* prettier fix for api/teams/profile
* removed noop import and added custom noop
* minor Button fix
* requested changes addressed
2021-09-06 13:22:22 +00:00
|
|
|
<p className="text-sm text-red-700">
|
2021-08-02 15:36:28 +00:00
|
|
|
<span className="font-bold">Error: </span>
|
|
|
|
{errorMessage}
|
2021-06-08 16:00:06 +00:00
|
|
|
</p>
|
2021-08-02 15:36:28 +00:00
|
|
|
)}
|
|
|
|
<div className="mt-5 sm:mt-4 sm:flex sm:flex-row-reverse">
|
2022-02-01 22:17:37 +00:00
|
|
|
<Button
|
|
|
|
type="submit"
|
|
|
|
color="primary"
|
|
|
|
className="ltr:ml-2 rtl:mr-2"
|
|
|
|
data-testid="invite-new-member-button">
|
2021-10-08 11:43:48 +00:00
|
|
|
{t("invite")}
|
Cal 262 refactor edit teams according to the design reference (#516)
* refactored settings/team landing page
* changed team edit flow, WIP
* merge conflict fix for teams.tsx
* minor fixes to edit team, WIP
* invite-member and disband team APIs attached inside edit-team page
* added remove-member API in edit-team page, minor fixes
* minor code fix, WIP
* WIP
* add logo, bio, branding to team schema
* bio, logo, branding, slug patch API and minor code fix-- WIP
* fn to Disband team directly from the dropdown menu in settings/teams page, removed debug remnants --WIP
* Pull latest data after an action in settings/teams-edit page
* added slug conflict check at Patch time
* code clean-up
* initial change request fixes --WIP
* prop type fix and add warn button color theme --WIP
* added warn Button to Dialog
* remaining change request fixes
* added noop from react-query
* updated invited team-list design
* prettier fix for api/teams/profile
* removed noop import and added custom noop
* minor Button fix
* requested changes addressed
2021-09-06 13:22:22 +00:00
|
|
|
</Button>
|
|
|
|
<Button type="button" color="secondary" onClick={props.onExit}>
|
2021-10-08 11:43:48 +00:00
|
|
|
{t("cancel")}
|
Cal 262 refactor edit teams according to the design reference (#516)
* refactored settings/team landing page
* changed team edit flow, WIP
* merge conflict fix for teams.tsx
* minor fixes to edit team, WIP
* invite-member and disband team APIs attached inside edit-team page
* added remove-member API in edit-team page, minor fixes
* minor code fix, WIP
* WIP
* add logo, bio, branding to team schema
* bio, logo, branding, slug patch API and minor code fix-- WIP
* fn to Disband team directly from the dropdown menu in settings/teams page, removed debug remnants --WIP
* Pull latest data after an action in settings/teams-edit page
* added slug conflict check at Patch time
* code clean-up
* initial change request fixes --WIP
* prop type fix and add warn button color theme --WIP
* added warn Button to Dialog
* remaining change request fixes
* added noop from react-query
* updated invited team-list design
* prettier fix for api/teams/profile
* removed noop import and added custom noop
* minor Button fix
* requested changes addressed
2021-09-06 13:22:22 +00:00
|
|
|
</Button>
|
2021-06-08 16:00:06 +00:00
|
|
|
</div>
|
2021-08-02 15:36:28 +00:00
|
|
|
</form>
|
2021-06-05 22:53:33 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-08-02 15:36:28 +00:00
|
|
|
);
|
2021-08-02 20:51:57 +00:00
|
|
|
}
|