2021-12-09 23:51:30 +00:00
|
|
|
import { UserIcon } from "@heroicons/react/outline";
|
|
|
|
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
|
|
|
|
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">
|
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="flex items-end justify-center min-h-screen px-4 pt-4 pb-20 text-center sm:block sm:p-0">
|
2021-08-08 19:21:33 +00:00
|
|
|
<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-0 transition-opacity bg-gray-500 bg-opacity-75"
|
2021-08-08 19:21:33 +00:00
|
|
|
aria-hidden="true"></div>
|
2021-06-05 22:53:33 +00:00
|
|
|
|
2021-08-02 15:36:28 +00:00
|
|
|
<span className="hidden sm:inline-block sm:align-middle sm:h-screen" aria-hidden="true">
|
|
|
|
​
|
|
|
|
</span>
|
2021-06-05 22:53:33 +00:00
|
|
|
|
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="inline-block px-4 pt-5 pb-4 text-left align-bottom transition-all transform bg-white rounded-lg shadow-xl sm:my-8 sm:align-middle sm:max-w-lg sm:w-full sm:p-6">
|
|
|
|
<div className="mb-4 sm:flex sm:items-start">
|
2021-12-14 10:39:32 +00:00
|
|
|
<div className="flex items-center justify-center flex-shrink-0 w-12 h-12 mx-auto rounded-full bg-brand text-brandcontrast bg-opacity-5 sm:mx-0 sm:h-10 sm:w-10">
|
|
|
|
<UserIcon className="w-6 h-6 text-brandcontrast" />
|
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}>
|
2021-06-08 16:00:06 +00:00
|
|
|
<div>
|
2021-08-02 15:36:28 +00:00
|
|
|
<div className="mb-4">
|
|
|
|
<label htmlFor="inviteUser" className="block text-sm font-medium text-gray-700">
|
2021-10-08 11:43:48 +00:00
|
|
|
{t("email_or_username")}
|
2021-08-02 15:36:28 +00:00
|
|
|
</label>
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
name="inviteUser"
|
|
|
|
id="inviteUser"
|
|
|
|
placeholder="email@example.com"
|
|
|
|
required
|
2021-11-04 14:30:37 +00:00
|
|
|
className="block w-full px-3 py-2 mt-1 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-black focus:border-brand sm:text-sm"
|
2021-08-02 15:36:28 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className="mb-4">
|
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
|
|
|
<label className="block mb-2 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"
|
2021-11-04 14:30:37 +00:00
|
|
|
className="block w-full mt-1 border-gray-300 rounded-md shadow-sm focus:ring-black focus:border-brand 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-10-08 11:43:48 +00:00
|
|
|
<option value="OWNER">{t("owner")}</option>
|
2021-08-02 15:36:28 +00:00
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
<div className="relative flex items-start">
|
|
|
|
<div className="flex items-center h-5">
|
|
|
|
<input
|
|
|
|
type="checkbox"
|
|
|
|
name="sendInviteEmail"
|
|
|
|
defaultChecked
|
|
|
|
id="sendInviteEmail"
|
2021-11-04 14:30:37 +00:00
|
|
|
className="text-black border-gray-300 rounded-md shadow-sm focus:ring-black focus:border-brand sm:text-sm"
|
2021-08-02 15:36:28 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className="ml-2 text-sm">
|
|
|
|
<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>
|
|
|
|
</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">
|
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 type="submit" color="primary" className="ml-2">
|
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
|
|
|
}
|