Skip to content
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
16 changes: 10 additions & 6 deletions site/src/pages/WorkspaceSettingsPage/WorkspaceSettingsForm.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import TextField from "@mui/material/TextField";
import {
FormFields,
FormFooter,
FormSection,
HorizontalForm,
} from "components/Form/Form";
import { useFormik } from "formik";
import { FC } from "react";
import { type FC } from "react";
import * as Yup from "yup";
import {
nameValidator,
getFormHelpers,
onChangeTrimmed,
} from "utils/formUtils";
import TextField from "@mui/material/TextField";
import { Workspace } from "api/typesGenerated";
import { Alert } from "components/Alert/Alert";

export type WorkspaceSettingsFormValues = {
name: string;
Expand Down Expand Up @@ -42,10 +43,7 @@ export const WorkspaceSettingsForm: FC<{

return (
<HorizontalForm onSubmit={form.handleSubmit} data-testid="form">
<FormSection
title="General info"
description="The name of your new workspace."
>
<FormSection title="General" description="The name of your workspace.">
<FormFields>
<TextField
{...getFieldHelpers("name")}
Expand All @@ -55,6 +53,12 @@ export const WorkspaceSettingsForm: FC<{
fullWidth
label="Name"
/>
{form.values.name !== form.initialValues.name && (
<Alert severity="warning">
Depending on the template, renaming your workspace may be
destructive
</Alert>
)}
</FormFields>
</FormSection>
<FormFooter onCancel={onCancel} isLoading={isSubmitting} />
Expand Down
4 changes: 2 additions & 2 deletions site/src/utils/formUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ export const getFormHelpers =
};

export const onChangeTrimmed =
<T>(form: FormikContextType<T>, callback?: () => void) =>
<T>(form: FormikContextType<T>, callback?: (value: string) => void) =>
(event: ChangeEvent<HTMLInputElement>): void => {
event.target.value = event.target.value.trim();
form.handleChange(event);
callback && callback();
callback?.(event.target.value);
};

// REMARK: Keep these consts in sync with coderd/httpapi/httpapi.go
Expand Down