Make console buildable and relay-compilable
Signed-off-by: Émile Ré <nemile.re@gmail.com>
This commit is contained in:
@@ -1,195 +0,0 @@
|
||||
import {
|
||||
Button,
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogFooter,
|
||||
Field,
|
||||
Checkbox,
|
||||
Select,
|
||||
Option,
|
||||
useDialogRef,
|
||||
} from "@probo/ui";
|
||||
import type { PropsWithChildren } from "react";
|
||||
import { useTranslate } from "@probo/i18n";
|
||||
import { graphql } from "relay-runtime";
|
||||
import { useOrganizationId } from "/hooks/useOrganizationId";
|
||||
import { useMutationWithToasts } from "/hooks/useMutationWithToasts";
|
||||
import { z } from "zod";
|
||||
import { useFormWithSchema } from "/hooks/useFormWithSchema";
|
||||
import { Controller } from "react-hook-form";
|
||||
import { Suspense, use } from "react";
|
||||
import { getAssignableRoles } from "@probo/helpers";
|
||||
import { PermissionsContext } from "/providers/PermissionsContext";
|
||||
|
||||
const inviteMutation = graphql`
|
||||
mutation InviteUserDialogMutation(
|
||||
$input: InviteUserInput!
|
||||
$connections: [ID!]!
|
||||
) {
|
||||
inviteUser(input: $input) {
|
||||
invitationEdge @appendEdge(connections: $connections) {
|
||||
node {
|
||||
id
|
||||
email
|
||||
fullName
|
||||
role
|
||||
expiresAt
|
||||
acceptedAt
|
||||
createdAt
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const schema = z.object({
|
||||
email: z.string().email(),
|
||||
fullName: z.string(),
|
||||
role: z.enum(["OWNER", "ADMIN", "FULL", "VIEWER", "AUDITOR", "EMPLOYEE"]).default("VIEWER"),
|
||||
createPeople: z.boolean().default(false),
|
||||
});
|
||||
|
||||
type Props = PropsWithChildren & {
|
||||
connectionId?: string;
|
||||
onRefetch: () => void;
|
||||
};
|
||||
|
||||
function InviteUserDialogContent({ children, connectionId, onRefetch }: Props) {
|
||||
const { __ } = useTranslate();
|
||||
const organizationId = useOrganizationId();
|
||||
const { role: currentUserRole } = use(PermissionsContext);
|
||||
const assignableRoles = getAssignableRoles(currentUserRole);
|
||||
const [inviteUser, isInviting] = useMutationWithToasts(inviteMutation, {
|
||||
successMessage: __("Invitation sent successfully"),
|
||||
errorMessage: __("Failed to send invitation"),
|
||||
});
|
||||
const { register, handleSubmit, formState, reset, control } = useFormWithSchema(
|
||||
schema,
|
||||
{ defaultValues: { role: "VIEWER", createPeople: false } },
|
||||
);
|
||||
|
||||
const dialogRef = useDialogRef();
|
||||
|
||||
const onSubmit = handleSubmit((data) => {
|
||||
inviteUser({
|
||||
variables: {
|
||||
input: {
|
||||
organizationId,
|
||||
email: data.email,
|
||||
fullName: data.fullName,
|
||||
role: data.role,
|
||||
createPeople: data.createPeople,
|
||||
},
|
||||
connections: connectionId ? [connectionId] : ["SettingsPageInvitations_invitations"],
|
||||
},
|
||||
onCompleted: () => {
|
||||
reset();
|
||||
dialogRef.current?.close();
|
||||
onRefetch();
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
return (
|
||||
<Dialog
|
||||
title={__("Invite member")}
|
||||
trigger={children}
|
||||
className="max-w-lg"
|
||||
ref={dialogRef}
|
||||
>
|
||||
<form onSubmit={onSubmit}>
|
||||
<DialogContent padded className="space-y-4">
|
||||
<p className="text-txt-secondary text-sm">
|
||||
Send an invitation to join your workspace.
|
||||
</p>
|
||||
<Field
|
||||
type="email"
|
||||
label={__("Email")}
|
||||
placeholder={__("Email")}
|
||||
{...register("email")}
|
||||
error={formState.errors.email?.message}
|
||||
/>
|
||||
<Field
|
||||
type="text"
|
||||
label={__("Full name")}
|
||||
placeholder={__("Full name")}
|
||||
{...register("fullName")}
|
||||
error={formState.errors.fullName?.message}
|
||||
/>
|
||||
<Field label={__("Role")} required>
|
||||
<Controller
|
||||
name="role"
|
||||
control={control}
|
||||
render={({ field }) => (
|
||||
<>
|
||||
<Select value={field.value} onValueChange={field.onChange}>
|
||||
{assignableRoles.includes("OWNER") && <Option value="OWNER">{__("Owner")}</Option>}
|
||||
{assignableRoles.includes("ADMIN") && <Option value="ADMIN">{__("Admin")}</Option>}
|
||||
{assignableRoles.includes("VIEWER") && <Option value="VIEWER">{__("Viewer")}</Option>}
|
||||
{assignableRoles.includes("AUDITOR") && <Option value="AUDITOR">{__("Auditor")}</Option>}
|
||||
{assignableRoles.includes("EMPLOYEE") && <Option value="EMPLOYEE">{__("Employee")}</Option>}
|
||||
</Select>
|
||||
<div className="mt-2 text-sm text-txt-tertiary">
|
||||
{field.value === "OWNER" && (
|
||||
<p>{__("Full access to everything")}</p>
|
||||
)}
|
||||
{field.value === "ADMIN" && (
|
||||
<p>{__("Full access except organization setup and API keys")}</p>
|
||||
)}
|
||||
{field.value === "VIEWER" && (
|
||||
<p>{__("Read-only access")}</p>
|
||||
)}
|
||||
{field.value === "AUDITOR" && (
|
||||
<p>{__("Read-only access without settings, tasks and meetings")}</p>
|
||||
)}
|
||||
{field.value === "EMPLOYEE" && (
|
||||
<p>{__("Access to employee page")}</p>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
/>
|
||||
</Field>
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center space-x-3">
|
||||
<Controller
|
||||
name="createPeople"
|
||||
control={control}
|
||||
render={({ field }) => (
|
||||
<>
|
||||
<Checkbox
|
||||
checked={field.value ?? false}
|
||||
onChange={field.onChange}
|
||||
/>
|
||||
<label
|
||||
className="text-sm font-medium cursor-pointer"
|
||||
onClick={() => field.onChange(!field.value)}
|
||||
>
|
||||
{__("Create people record")}
|
||||
</label>
|
||||
</>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
<p className="text-xs text-txt-secondary ml-7">
|
||||
{__("Creates a people record for this user in addition to the user account")}
|
||||
</p>
|
||||
</div>
|
||||
</DialogContent>
|
||||
<DialogFooter>
|
||||
<Button type="submit" disabled={isInviting}>
|
||||
{__("Invite user")}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</form>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
export function InviteUserDialog(props: Props) {
|
||||
return (
|
||||
<Suspense fallback={props.children}>
|
||||
<InviteUserDialogContent {...props} />
|
||||
</Suspense>
|
||||
);
|
||||
}
|
||||
@@ -1,211 +0,0 @@
|
||||
/**
|
||||
* @generated SignedSource<<b1826b0f39e35064b4f2c8bc9691f63a>>
|
||||
* @lightSyntaxTransform
|
||||
* @nogrep
|
||||
*/
|
||||
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
|
||||
import { ConcreteRequest } from 'relay-runtime';
|
||||
export type MembershipRole = "ADMIN" | "AUDITOR" | "EMPLOYEE" | "OWNER" | "VIEWER";
|
||||
export type InviteUserInput = {
|
||||
createPeople: boolean;
|
||||
email: any;
|
||||
fullName: string;
|
||||
organizationId: string;
|
||||
role: MembershipRole;
|
||||
};
|
||||
export type InviteUserDialogMutation$variables = {
|
||||
connections: ReadonlyArray<string>;
|
||||
input: InviteUserInput;
|
||||
};
|
||||
export type InviteUserDialogMutation$data = {
|
||||
readonly inviteUser: {
|
||||
readonly invitationEdge: {
|
||||
readonly node: {
|
||||
readonly acceptedAt: any | null | undefined;
|
||||
readonly createdAt: any;
|
||||
readonly email: any;
|
||||
readonly expiresAt: any;
|
||||
readonly fullName: string;
|
||||
readonly id: string;
|
||||
readonly role: MembershipRole;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
export type InviteUserDialogMutation = {
|
||||
response: InviteUserDialogMutation$data;
|
||||
variables: InviteUserDialogMutation$variables;
|
||||
};
|
||||
|
||||
const node: ConcreteRequest = (function(){
|
||||
var v0 = {
|
||||
"defaultValue": null,
|
||||
"kind": "LocalArgument",
|
||||
"name": "connections"
|
||||
},
|
||||
v1 = {
|
||||
"defaultValue": null,
|
||||
"kind": "LocalArgument",
|
||||
"name": "input"
|
||||
},
|
||||
v2 = [
|
||||
{
|
||||
"kind": "Variable",
|
||||
"name": "input",
|
||||
"variableName": "input"
|
||||
}
|
||||
],
|
||||
v3 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "InvitationEdge",
|
||||
"kind": "LinkedField",
|
||||
"name": "invitationEdge",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "Invitation",
|
||||
"kind": "LinkedField",
|
||||
"name": "node",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "id",
|
||||
"storageKey": null
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "email",
|
||||
"storageKey": null
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "fullName",
|
||||
"storageKey": null
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "role",
|
||||
"storageKey": null
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "expiresAt",
|
||||
"storageKey": null
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "acceptedAt",
|
||||
"storageKey": null
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "createdAt",
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
};
|
||||
return {
|
||||
"fragment": {
|
||||
"argumentDefinitions": [
|
||||
(v0/*: any*/),
|
||||
(v1/*: any*/)
|
||||
],
|
||||
"kind": "Fragment",
|
||||
"metadata": null,
|
||||
"name": "InviteUserDialogMutation",
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": (v2/*: any*/),
|
||||
"concreteType": "InviteUserPayload",
|
||||
"kind": "LinkedField",
|
||||
"name": "inviteUser",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
(v3/*: any*/)
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"type": "Mutation",
|
||||
"abstractKey": null
|
||||
},
|
||||
"kind": "Request",
|
||||
"operation": {
|
||||
"argumentDefinitions": [
|
||||
(v1/*: any*/),
|
||||
(v0/*: any*/)
|
||||
],
|
||||
"kind": "Operation",
|
||||
"name": "InviteUserDialogMutation",
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": (v2/*: any*/),
|
||||
"concreteType": "InviteUserPayload",
|
||||
"kind": "LinkedField",
|
||||
"name": "inviteUser",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
(v3/*: any*/),
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"filters": null,
|
||||
"handle": "appendEdge",
|
||||
"key": "",
|
||||
"kind": "LinkedHandle",
|
||||
"name": "invitationEdge",
|
||||
"handleArgs": [
|
||||
{
|
||||
"kind": "Variable",
|
||||
"name": "connections",
|
||||
"variableName": "connections"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
]
|
||||
},
|
||||
"params": {
|
||||
"cacheID": "2f6a83e238f7749e18757ec74e86b64b",
|
||||
"id": null,
|
||||
"metadata": {},
|
||||
"name": "InviteUserDialogMutation",
|
||||
"operationKind": "mutation",
|
||||
"text": "mutation InviteUserDialogMutation(\n $input: InviteUserInput!\n) {\n inviteUser(input: $input) {\n invitationEdge {\n node {\n id\n email\n fullName\n role\n expiresAt\n acceptedAt\n createdAt\n }\n }\n }\n}\n"
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
(node as any).hash = "3981061f31a11e83ad32bed9fabddf64";
|
||||
|
||||
export default node;
|
||||
Reference in New Issue
Block a user