-
Notifications
You must be signed in to change notification settings - Fork 5
/
InvitedAccountAction.tsx
104 lines (99 loc) · 3.45 KB
/
InvitedAccountAction.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import { ActionIcon, Button, Group, Menu, Text } from "@mantine/core"
import { Form, Link, useNavigation } from "@remix-run/react"
import React from "react"
import { LuArrowUpRight, LuMinusCircle, LuMoreHorizontal, LuPencil } from "react-icons/lu"
import { RoleName, User } from "~/models/portal/sdk"
import useTeamModals from "~/routes/account.$accountId.settings.members/hooks/useTeamModals"
import { TableUserAccount } from "~/routes/user.accounts/components/AccountsTable"
import { AnalyticActions, AnalyticCategories, trackEvent } from "~/utils/analytics"
type InvitedAccountActionProps = {
account: TableUserAccount
user: User
}
const InvitedAccountAction = ({ account, user }: InvitedAccountActionProps) => {
const navigation = useNavigation()
const { accepted, role } = account
const { openLeaveTeamModal } = useTeamModals({ account })
return (
<Group gap="md" grow={!accepted} justify="right">
{accepted ? (
<Menu>
<Menu.Target>
<ActionIcon
aria-label="Open account actions menu"
radius="xl"
size={40}
variant="outline"
>
<LuMoreHorizontal />
</ActionIcon>
</Menu.Target>
<Menu.Dropdown>
<Menu.Item leftSection={<LuArrowUpRight size={18} />}>
<Link to={`/account/${account.id}`}>
<Text tt="capitalize">Go to account</Text>
</Link>
</Menu.Item>
{role === RoleName.Owner ? (
<Menu.Item leftSection={<LuPencil size={18} />}>
<Link to={`/account/${account.id}/update?redirectTo=/user/accounts`}>
<Text tt="capitalize">Change name</Text>
</Link>
</Menu.Item>
) : (
<Menu.Item
leftSection={<LuMinusCircle size={18} />}
onClick={() =>
openLeaveTeamModal({ email: user.email, id: user.portalUserID })
}
>
<Text>Leave</Text>
</Menu.Item>
)}
</Menu.Dropdown>
</Menu>
) : (
<Form method="post">
<input hidden name="accountId" value={account.id} />
<input hidden name="accountName" value={account.name ?? ""} />
<input hidden name="role" value={role} />
<Group justify="right">
<Button
color="gray"
disabled={navigation.state === "loading"}
name="invite_response"
type="submit"
value="decline"
variant="outline"
onClick={() => {
trackEvent({
category: AnalyticCategories.user,
action: AnalyticActions.user_invites_decline,
label: account.id,
})
}}
>
Decline
</Button>
<Button
disabled={navigation.state === "loading"}
name="invite_response"
type="submit"
value="accept"
onClick={() => {
trackEvent({
category: AnalyticCategories.user,
action: AnalyticActions.user_invites_accept,
label: account.id,
})
}}
>
Accept
</Button>
</Group>
</Form>
)}
</Group>
)
}
export default InvitedAccountAction