-
Notifications
You must be signed in to change notification settings - Fork 454
/
ShowLicenseInfo.tsx
175 lines (167 loc) · 6.31 KB
/
ShowLicenseInfo.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import { FC, useState } from "react";
import { FaPencilAlt } from "react-icons/fa";
import { date } from "shared/dates";
import usePermissions from "@/hooks/usePermissions";
import { useUser } from "@/services/UserContext";
import EditLicenseModal from "@/components/Settings/EditLicenseModal";
import { GBPremiumBadge } from "@/components/Icons";
import UpgradeModal from "@/components/Settings/UpgradeModal";
import AccountPlanNotices from "@/components/Layout/AccountPlanNotices";
import { isCloud } from "@/services/env";
import RefreshLicenseButton from "./RefreshLicenseButton";
import DownloadLicenseUsageButton from "./DownloadLicenseUsageButton";
const ShowLicenseInfo: FC<{
showInput?: boolean;
}> = ({ showInput = true }) => {
const { accountPlan, license, refreshOrganization, organization } = useUser();
const permissions = usePermissions();
const [editLicenseOpen, setEditLicenseOpen] = useState(false);
const [upgradeModal, setUpgradeModal] = useState(false);
// The accountPlan is the effective plan given possible downgrades.
// but we want to show the actual plan on the license.
const actualPlan = license?.plan || accountPlan;
const showUpgradeButton = ["oss", "starter"].includes(actualPlan || "");
const licensePlanText =
(actualPlan === "enterprise"
? "Enterprise"
: actualPlan === "pro"
? "Pro"
: actualPlan === "pro_sso"
? "Pro + SSO"
: "Starter") + (license && license.isTrial ? " (trial)" : "");
// TODO: Remove this once we have migrated all organizations to use the license key
const usesLicenseInfoOnModel =
isCloud() && !showUpgradeButton && !organization?.licenseKey;
return (
<div>
{upgradeModal && (
<UpgradeModal
close={() => setUpgradeModal(false)}
reason=""
source="settings"
/>
)}
{editLicenseOpen && (
<EditLicenseModal
close={() => setEditLicenseOpen(false)}
mutate={refreshOrganization}
/>
)}
<div>
<div className="divider border-bottom mb-3 mt-3" />
<div className="row">
<div className="col-sm-3">
<h4>License</h4>
</div>
<div className="col-sm-9">
<div className="form-group row mb-2">
<div className="col-sm-12">
<strong>Plan type: </strong> {licensePlanText}{" "}
</div>
<AccountPlanNotices />
</div>
{showUpgradeButton && (
<div className="form-group row mb-1">
<div className="col-sm-12">
<button
className="btn btn-premium font-weight-normal"
onClick={() => setUpgradeModal(true)}
>
<>
Upgrade <GBPremiumBadge />
</>
</button>
</div>
</div>
)}
{permissions.manageBilling && !usesLicenseInfoOnModel && (
<div className="form-group row mt-3 mb-0">
{showInput && (
<div className="col-sm-2">
<div>
<strong>License Key: </strong>
</div>
<div
className="d-inline-block mt-1 mb-2 text-center text-muted"
style={{
width: 100,
borderBottom: "1px solid #cccccc",
pointerEvents: "none",
overflow: "hidden",
verticalAlign: "top",
}}
>
{license ? "***************" : "(none)"}
</div>{" "}
<a
href="#"
className="pl-1"
onClick={(e) => {
e.preventDefault();
setEditLicenseOpen(true);
}}
>
<FaPencilAlt />
</a>
</div>
)}
{license &&
license.plan && ( // A license might not have a plan if a stripe pro form is not filled out
<>
{["pro", "pro_sso"].includes(license.plan) && (
<div className="col-sm-2">
<div>Status:</div>
<span
className={`text-muted ${
!["active", "trialing"].includes(
license.stripeSubscription?.status || ""
)
? "alert-danger"
: ""
}`}
>
{license.stripeSubscription?.status}
</span>
</div>
)}
<div className="col-sm-2">
<div>Issued:</div>
<span className="text-muted">
{date(license.dateCreated)}
</span>
</div>
<div className="col-sm-2">
<div>Expires:</div>
<span className="text-muted">
{date(license.dateExpires)}
</span>
</div>
<div className="col-sm-2">
<div>Seats:</div>
<span className="text-muted">{license.seats}</span>
</div>
</>
)}
{license && (
<>
{license.id.startsWith("license") && (
<div className="col-sm-2">
<RefreshLicenseButton />
</div>
)}
{!license.id.startsWith("license") && (
<div className="mt-3">
<DownloadLicenseUsageButton />
</div>
)}
</>
)}
</div>
)}
</div>
</div>
</div>
</div>
);
};
export default ShowLicenseInfo;