forked from github/plane
4f72ebded9
* chore: added event constants * chore: added workspace events * chore: added workspace group for events * chore: member invitation event added * chore: added project pages related events. * fix: member integer role to string * chore: added sign-up & sign-in events * chore: added global-view related events * chore: added notification related events * chore: project, cycle property change added * chore: cycle favourite, and change-properties added * chore: module davorite, and sidebar property changes added * fix: build errors * chore: all events defined in constants
130 lines
4.4 KiB
TypeScript
130 lines
4.4 KiB
TypeScript
import { useState, ReactElement } from "react";
|
|
import { useRouter } from "next/router";
|
|
import { observer } from "mobx-react-lite";
|
|
import { Search } from "lucide-react";
|
|
// hooks
|
|
import { useEventTracker, useMember, useUser } from "hooks/store";
|
|
import useToast from "hooks/use-toast";
|
|
// layouts
|
|
import { AppLayout } from "layouts/app-layout";
|
|
import { WorkspaceSettingLayout } from "layouts/settings-layout";
|
|
// components
|
|
import { WorkspaceSettingHeader } from "components/headers";
|
|
import { SendWorkspaceInvitationModal, WorkspaceMembersList } from "components/workspace";
|
|
// ui
|
|
import { Button } from "@plane/ui";
|
|
// types
|
|
import { NextPageWithLayout } from "lib/types";
|
|
import { IWorkspaceBulkInviteFormData } from "@plane/types";
|
|
// helpers
|
|
import { getUserRole } from "helpers/user.helper";
|
|
// constants
|
|
import { EUserWorkspaceRoles } from "constants/workspace";
|
|
import { MEMBER_INVITED } from "constants/event-tracker";
|
|
|
|
const WorkspaceMembersSettingsPage: NextPageWithLayout = observer(() => {
|
|
// states
|
|
const [inviteModal, setInviteModal] = useState(false);
|
|
const [searchQuery, setSearchQuery] = useState<string>("");
|
|
// router
|
|
const router = useRouter();
|
|
const { workspaceSlug } = router.query;
|
|
// store hooks
|
|
const { captureEvent, setTrackElement } = useEventTracker();
|
|
const {
|
|
membership: { currentWorkspaceRole },
|
|
} = useUser();
|
|
const {
|
|
workspace: { inviteMembersToWorkspace },
|
|
} = useMember();
|
|
// toast alert
|
|
const { setToastAlert } = useToast();
|
|
|
|
const handleWorkspaceInvite = (data: IWorkspaceBulkInviteFormData) => {
|
|
if (!workspaceSlug) return;
|
|
|
|
return inviteMembersToWorkspace(workspaceSlug.toString(), data)
|
|
.then(() => {
|
|
setInviteModal(false);
|
|
captureEvent(MEMBER_INVITED, {
|
|
emails: [
|
|
...data.emails.map((email) => ({
|
|
email: email.email,
|
|
role: getUserRole(email.role),
|
|
})),
|
|
],
|
|
project_id: undefined,
|
|
state: "SUCCESS",
|
|
element: "Workspace settings member page",
|
|
});
|
|
setToastAlert({
|
|
type: "success",
|
|
title: "Success!",
|
|
message: "Invitations sent successfully.",
|
|
});
|
|
})
|
|
.catch((err) => {
|
|
captureEvent(MEMBER_INVITED, {
|
|
emails: [
|
|
...data.emails.map((email) => ({
|
|
email: email.email,
|
|
role: getUserRole(email.role),
|
|
})),
|
|
],
|
|
project_id: undefined,
|
|
state: "FAILED",
|
|
element: "Workspace settings member page",
|
|
});
|
|
setToastAlert({
|
|
type: "error",
|
|
title: "Error!",
|
|
message: `${err.error ?? "Something went wrong. Please try again."}`,
|
|
});
|
|
});
|
|
};
|
|
|
|
const hasAddMemberPermission =
|
|
currentWorkspaceRole && [EUserWorkspaceRoles.ADMIN, EUserWorkspaceRoles.MEMBER].includes(currentWorkspaceRole);
|
|
|
|
return (
|
|
<>
|
|
<SendWorkspaceInvitationModal
|
|
isOpen={inviteModal}
|
|
onClose={() => setInviteModal(false)}
|
|
onSubmit={handleWorkspaceInvite}
|
|
/>
|
|
<section className="w-full overflow-y-auto py-8 pr-9">
|
|
<div className="flex items-center justify-between gap-4 border-b border-custom-border-100 py-3.5">
|
|
<h4 className="text-xl font-medium">Members</h4>
|
|
<div className="ml-auto flex items-center gap-1.5 rounded-md border border-custom-border-200 bg-custom-background-100 px-2.5 py-1.5">
|
|
<Search className="h-3.5 w-3.5 text-custom-text-400" />
|
|
<input
|
|
className="w-full max-w-[234px] border-none bg-transparent text-sm outline-none placeholder:text-custom-text-400"
|
|
placeholder="Search..."
|
|
value={searchQuery}
|
|
autoFocus
|
|
onChange={(e) => setSearchQuery(e.target.value)}
|
|
/>
|
|
</div>
|
|
{hasAddMemberPermission && (
|
|
<Button variant="primary" size="sm" onClick={() => setInviteModal(true)}>
|
|
Add member
|
|
</Button>
|
|
)}
|
|
</div>
|
|
<WorkspaceMembersList searchQuery={searchQuery} />
|
|
</section>
|
|
</>
|
|
);
|
|
});
|
|
|
|
WorkspaceMembersSettingsPage.getLayout = function getLayout(page: ReactElement) {
|
|
return (
|
|
<AppLayout header={<WorkspaceSettingHeader title="Members Settings" />}>
|
|
<WorkspaceSettingLayout>{page}</WorkspaceSettingLayout>
|
|
</AppLayout>
|
|
);
|
|
};
|
|
|
|
export default WorkspaceMembersSettingsPage;
|