Skip to content

Improve Workspace timeout settings error UX #18925

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
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
41 changes: 25 additions & 16 deletions components/dashboard/src/user-settings/Preferences.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default function Preferences() {
const [dotfileRepo, setDotfileRepo] = useState<string>(user?.additionalData?.dotfileRepo || "");
const [workspaceTimeout, setWorkspaceTimeout] = useState<string>(user?.additionalData?.workspaceTimeout ?? "");
const [timeoutUpdating, setTimeoutUpdating] = useState(false);
const [creationError, setCreationError] = useState<Error>();

const saveDotfileRepo = useCallback(
async (e) => {
Expand Down Expand Up @@ -70,10 +71,11 @@ export default function Preferences() {
);
}
}
// Reset creationError to avoid displaying the error message and toast the success message
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would have been a good opportunity to refactor this into a react-query mutation, which handles the error state for us automatically.

setCreationError(undefined);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I probably would have gone with a toast here for the error instead of an inline one.

toast(toastMessage);
} catch (e) {
// TODO: Convert this to an error style toast
alert("Cannot set custom workspace timeout: " + e.message);
setCreationError(new Error(e.message));
} finally {
setTimeoutUpdating(false);
}
Expand Down Expand Up @@ -159,21 +161,28 @@ export default function Preferences() {
</span>
}
>
<div className="flex space-x-2">
<div className="flex-grow">
<TextInput
value={workspaceTimeout}
placeholder="e.g. 30m"
onChange={setWorkspaceTimeout}
/>
<div className="flex flex-col">
<div className="flex items-center space-x-2 mb-2">
<div className="flex-grow">
<TextInput
value={workspaceTimeout}
placeholder="e.g. 30m"
onChange={setWorkspaceTimeout}
/>
</div>
<Button
htmlType="submit"
loading={timeoutUpdating}
disabled={workspaceTimeout === user?.additionalData?.workspaceTimeout ?? ""}
>
Save
</Button>
</div>
<Button
htmlType="submit"
loading={timeoutUpdating}
disabled={workspaceTimeout === user?.additionalData?.workspaceTimeout ?? ""}
>
Save
</Button>
{!!creationError && (
<p className="text-gitpod-red w-full max-w-lg">
Cannot set custom workspace timeout: {creationError.message}
</p>
)}
</div>
</InputField>
</form>
Expand Down