Skip to content

fix: display trial errors in the dashboard #13601

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func (r *RootCmd) login() *serpent.Command {

if !inv.ParsedFlags().Changed("first-user-trial") && os.Getenv(firstUserTrialEnv) == "" {
v, _ := cliui.Prompt(inv, cliui.PromptOptions{
Text: "Start a 30-day trial of Enterprise?",
Text: "Start a trial of Enterprise?",
IsConfirm: true,
Default: "yes",
})
Expand Down
16 changes: 16 additions & 0 deletions enterprise/trialer/trialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ func New(db database.Store, url string, keys map[string]ed25519.PublicKey) func(
return xerrors.Errorf("perform license request: %w", err)
}
defer res.Body.Close()
if res.StatusCode > 300 {
body, err := io.ReadAll(res.Body)
if err != nil {
return xerrors.Errorf("read license response: %w", err)
}
// This is the format of the error response from
// the license server.
var msg struct {
Error string `json:"error"`
}
err = json.Unmarshal(body, &msg)
if err != nil {
return xerrors.Errorf("unmarshal error: %w", err)
}
return xerrors.New(msg.Error)
}
raw, err := io.ReadAll(res.Body)
if err != nil {
return xerrors.Errorf("read license: %w", err)
Expand Down
9 changes: 9 additions & 0 deletions site/src/pages/SetupPage/SetupPageView.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ export const FormError: Story = {
},
};

export const TrialError: Story = {
args: {
error: mockApiError({
message: "Couldn't generate trial!",
detail: "It looks like your team is already trying Coder.",
}),
},
};

export const Loading: Story = {
args: {
isLoading: true,
Expand Down
20 changes: 19 additions & 1 deletion site/src/pages/SetupPage/SetupPageView.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import LoadingButton from "@mui/lab/LoadingButton";
import AlertTitle from "@mui/material/AlertTitle";
import Autocomplete from "@mui/material/Autocomplete";
import Checkbox from "@mui/material/Checkbox";
import Link from "@mui/material/Link";
import MenuItem from "@mui/material/MenuItem";
import TextField from "@mui/material/TextField";
import { isAxiosError } from "axios";
import { type FormikContextType, useFormik } from "formik";
import type { FC } from "react";
import * as Yup from "yup";
import type * as TypesGen from "api/typesGenerated";
import { Alert, AlertDetail } from "components/Alert/Alert";
import { FormFields, VerticalForm } from "components/Form/Form";
import { CoderIcon } from "components/Icons/CoderIcon";
import { SignInLayout } from "components/SignInLayout/SignInLayout";
Expand Down Expand Up @@ -187,7 +190,7 @@ export const SetupPageView: FC<SetupPageViewProps> = ({

<div css={{ fontSize: 14, paddingTop: 4 }}>
<span css={{ display: "block", fontWeight: 600 }}>
Start a 30-day free trial of Enterprise
Start a free trial of Enterprise
</span>
<span
css={(theme) => ({
Expand Down Expand Up @@ -316,6 +319,21 @@ export const SetupPageView: FC<SetupPageViewProps> = ({
</>
)}

{isAxiosError(error) && error.response?.data?.message && (
<Alert severity="error">
<AlertTitle>{error.response.data.message}</AlertTitle>
{error.response.data.detail && (
<AlertDetail>
{error.response.data.detail}
<br />
<Link target="_blank" href="https://coder.com/contact/sales">
Contact Sales
</Link>
</AlertDetail>
)}
</Alert>
)}

<LoadingButton
fullWidth
loading={isLoading}
Expand Down
Loading