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
This commit is contained in:
Kyle Carberry
2024-06-19 12:02:51 -04:00
committed by GitHub
parent 84cdcac8ad
commit 7049d7a881
4 changed files with 45 additions and 2 deletions
+1 -1
View File
@@ -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",
})
+16
View File
@@ -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)
@@ -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,
+19 -1
View File
@@ -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";
@@ -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) => ({
@@ -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}