Skip to content

Commit e6aeee2

Browse files
authored
feat: warn users when renaming workspaces (#10023)
1 parent 4df5c1d commit e6aeee2

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

site/src/pages/WorkspaceSettingsPage/WorkspaceSettingsForm.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1+
import TextField from "@mui/material/TextField";
12
import {
23
FormFields,
34
FormFooter,
45
FormSection,
56
HorizontalForm,
67
} from "components/Form/Form";
78
import { useFormik } from "formik";
8-
import { FC } from "react";
9+
import { type FC } from "react";
910
import * as Yup from "yup";
1011
import {
1112
nameValidator,
1213
getFormHelpers,
1314
onChangeTrimmed,
1415
} from "utils/formUtils";
15-
import TextField from "@mui/material/TextField";
1616
import { Workspace } from "api/typesGenerated";
17+
import { Alert } from "components/Alert/Alert";
1718

1819
export type WorkspaceSettingsFormValues = {
1920
name: string;
@@ -42,10 +43,7 @@ export const WorkspaceSettingsForm: FC<{
4243

4344
return (
4445
<HorizontalForm onSubmit={form.handleSubmit} data-testid="form">
45-
<FormSection
46-
title="General info"
47-
description="The name of your new workspace."
48-
>
46+
<FormSection title="General" description="The name of your workspace.">
4947
<FormFields>
5048
<TextField
5149
{...getFieldHelpers("name")}
@@ -55,6 +53,12 @@ export const WorkspaceSettingsForm: FC<{
5553
fullWidth
5654
label="Name"
5755
/>
56+
{form.values.name !== form.initialValues.name && (
57+
<Alert severity="warning">
58+
Depending on the template, renaming your workspace may be
59+
destructive
60+
</Alert>
61+
)}
5862
</FormFields>
5963
</FormSection>
6064
<FormFooter onCancel={onCancel} isLoading={isSubmitting} />

site/src/utils/formUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ export const getFormHelpers =
6464
};
6565

6666
export const onChangeTrimmed =
67-
<T>(form: FormikContextType<T>, callback?: () => void) =>
67+
<T>(form: FormikContextType<T>, callback?: (value: string) => void) =>
6868
(event: ChangeEvent<HTMLInputElement>): void => {
6969
event.target.value = event.target.value.trim();
7070
form.handleChange(event);
71-
callback && callback();
71+
callback?.(event.target.value);
7272
};
7373

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

0 commit comments

Comments
 (0)