Skip to content

Commit 7049d7a

Browse files
authored
fix: display trial errors in the dashboard (#13601)
* fix: display trial errors in the dashboard The error was essentially being ignored before! * Remove day mention in product of trial * fmt
1 parent 84cdcac commit 7049d7a

File tree

4 files changed

+45
-2
lines changed

4 files changed

+45
-2
lines changed

cli/login.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ func (r *RootCmd) login() *serpent.Command {
239239

240240
if !inv.ParsedFlags().Changed("first-user-trial") && os.Getenv(firstUserTrialEnv) == "" {
241241
v, _ := cliui.Prompt(inv, cliui.PromptOptions{
242-
Text: "Start a 30-day trial of Enterprise?",
242+
Text: "Start a trial of Enterprise?",
243243
IsConfirm: true,
244244
Default: "yes",
245245
})

enterprise/trialer/trialer.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,22 @@ func New(db database.Store, url string, keys map[string]ed25519.PublicKey) func(
3939
return xerrors.Errorf("perform license request: %w", err)
4040
}
4141
defer res.Body.Close()
42+
if res.StatusCode > 300 {
43+
body, err := io.ReadAll(res.Body)
44+
if err != nil {
45+
return xerrors.Errorf("read license response: %w", err)
46+
}
47+
// This is the format of the error response from
48+
// the license server.
49+
var msg struct {
50+
Error string `json:"error"`
51+
}
52+
err = json.Unmarshal(body, &msg)
53+
if err != nil {
54+
return xerrors.Errorf("unmarshal error: %w", err)
55+
}
56+
return xerrors.New(msg.Error)
57+
}
4258
raw, err := io.ReadAll(res.Body)
4359
if err != nil {
4460
return xerrors.Errorf("read license: %w", err)

site/src/pages/SetupPage/SetupPageView.stories.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ export const FormError: Story = {
2222
},
2323
};
2424

25+
export const TrialError: Story = {
26+
args: {
27+
error: mockApiError({
28+
message: "Couldn't generate trial!",
29+
detail: "It looks like your team is already trying Coder.",
30+
}),
31+
},
32+
};
33+
2534
export const Loading: Story = {
2635
args: {
2736
isLoading: true,

site/src/pages/SetupPage/SetupPageView.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import LoadingButton from "@mui/lab/LoadingButton";
2+
import AlertTitle from "@mui/material/AlertTitle";
23
import Autocomplete from "@mui/material/Autocomplete";
34
import Checkbox from "@mui/material/Checkbox";
45
import Link from "@mui/material/Link";
56
import MenuItem from "@mui/material/MenuItem";
67
import TextField from "@mui/material/TextField";
8+
import { isAxiosError } from "axios";
79
import { type FormikContextType, useFormik } from "formik";
810
import type { FC } from "react";
911
import * as Yup from "yup";
1012
import type * as TypesGen from "api/typesGenerated";
13+
import { Alert, AlertDetail } from "components/Alert/Alert";
1114
import { FormFields, VerticalForm } from "components/Form/Form";
1215
import { CoderIcon } from "components/Icons/CoderIcon";
1316
import { SignInLayout } from "components/SignInLayout/SignInLayout";
@@ -187,7 +190,7 @@ export const SetupPageView: FC<SetupPageViewProps> = ({
187190

188191
<div css={{ fontSize: 14, paddingTop: 4 }}>
189192
<span css={{ display: "block", fontWeight: 600 }}>
190-
Start a 30-day free trial of Enterprise
193+
Start a free trial of Enterprise
191194
</span>
192195
<span
193196
css={(theme) => ({
@@ -316,6 +319,21 @@ export const SetupPageView: FC<SetupPageViewProps> = ({
316319
</>
317320
)}
318321

322+
{isAxiosError(error) && error.response?.data?.message && (
323+
<Alert severity="error">
324+
<AlertTitle>{error.response.data.message}</AlertTitle>
325+
{error.response.data.detail && (
326+
<AlertDetail>
327+
{error.response.data.detail}
328+
<br />
329+
<Link target="_blank" href="https://coder.com/contact/sales">
330+
Contact Sales
331+
</Link>
332+
</AlertDetail>
333+
)}
334+
</Alert>
335+
)}
336+
319337
<LoadingButton
320338
fullWidth
321339
loading={isLoading}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy