Skip to content

feat: warn users when renaming workspaces #10023

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 2 commits into from
Oct 3, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
huh!
  • Loading branch information
aslilac committed Oct 3, 2023
commit 0d1dbfcc2913b8da73ba0ea7ff3580146cd96d98
12 changes: 3 additions & 9 deletions site/src/pages/WorkspaceSettingsPage/WorkspaceSettingsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
HorizontalForm,
} from "components/Form/Form";
import { useFormik } from "formik";
import { type FC, useState } from "react";
import { type FC } from "react";
import * as Yup from "yup";
import {
nameValidator,
Expand Down Expand Up @@ -41,25 +41,19 @@ export const WorkspaceSettingsForm: FC<{
error,
);

// We can't use `form.touched` unfortunately, because it only gets updated
// when a field loses focus, not when it gets changed.
const [nameModified, setNameModified] = useState(false);

return (
<HorizontalForm onSubmit={form.handleSubmit} data-testid="form">
<FormSection title="General" description="The name of your workspace.">
<FormFields>
<TextField
{...getFieldHelpers("name")}
disabled={form.isSubmitting}
onChange={onChangeTrimmed(form, (value) =>
setNameModified(value !== form.initialValues.name),
)}
onChange={onChangeTrimmed(form)}
autoFocus
fullWidth
label="Name"
/>
{nameModified && (
{form.values.name !== form.initialValues.name && (
<Alert severity="warning">
Depending on the template, renaming your workspace may be
destructive
Expand Down