Skip to content

Commit 2a085d1

Browse files
authored
chore: refactor dialogs (coder#3935)
* Move dialogs * Repurpose WorkspaceDeleteDialog * Rename to DeleteDialog Pausing on the typing part for now, leaving this as a refactor * Rename handlers
1 parent 47ee44e commit 2a085d1

File tree

18 files changed

+94
-81
lines changed

18 files changed

+94
-81
lines changed

site/src/components/DeleteWorkspaceDialog/DeleteWorkspaceDialog.stories.tsx

Lines changed: 0 additions & 29 deletions
This file was deleted.

site/src/components/DeleteWorkspaceDialog/DeleteWorkspaceDialog.tsx

Lines changed: 0 additions & 27 deletions
This file was deleted.

site/src/components/ConfirmDialog/ConfirmDialog.test.tsx renamed to site/src/components/Dialogs/ConfirmDialog/ConfirmDialog.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { fireEvent, render } from "@testing-library/react"
22
import { FC } from "react"
3-
import { WrapperComponent } from "../../testHelpers/renderHelpers"
3+
import { WrapperComponent } from "../../../testHelpers/renderHelpers"
44
import { ConfirmDialog, ConfirmDialogProps } from "./ConfirmDialog"
55

66
namespace Helpers {

site/src/components/ConfirmDialog/ConfirmDialog.tsx renamed to site/src/components/Dialogs/ConfirmDialog/ConfirmDialog.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import DialogActions from "@material-ui/core/DialogActions"
22
import { fade, makeStyles } from "@material-ui/core/styles"
33
import Typography from "@material-ui/core/Typography"
44
import React, { ReactNode } from "react"
5-
import { Dialog, DialogActionButtons, DialogActionButtonsProps } from "../Dialog/Dialog"
6-
import { ConfirmDialogType } from "../Dialog/types"
5+
import { Dialog, DialogActionButtons, DialogActionButtonsProps } from "../Dialog"
6+
import { ConfirmDialogType } from "../types"
77

88
interface ConfirmDialogTypeConfig {
99
confirmText: ReactNode
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { ComponentMeta, Story } from "@storybook/react"
2+
import { DeleteDialog, DeleteDialogProps } from "./DeleteDialog"
3+
4+
export default {
5+
title: "Components/Dialogs/DeleteDialog",
6+
component: DeleteDialog,
7+
argTypes: {
8+
onCancel: {
9+
action: "onClose",
10+
},
11+
onConfirm: {
12+
action: "onConfirm",
13+
},
14+
open: {
15+
control: "boolean",
16+
defaultValue: true,
17+
},
18+
title: {
19+
defaultValue: "Delete Something",
20+
},
21+
description: {
22+
defaultValue:
23+
"This is irreversible. To confirm, type the name of the thing you want to delete.",
24+
},
25+
},
26+
} as ComponentMeta<typeof DeleteDialog>
27+
28+
const Template: Story<DeleteDialogProps> = (args) => <DeleteDialog {...args} />
29+
30+
export const Example = Template.bind({})
31+
Example.args = {
32+
isOpen: true,
33+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import React, { ReactNode } from "react"
2+
import { ConfirmDialog } from "../ConfirmDialog/ConfirmDialog"
3+
4+
export interface DeleteDialogProps {
5+
isOpen: boolean
6+
onConfirm: () => void
7+
onCancel: () => void
8+
title: string
9+
description: string | ReactNode
10+
confirmLoading?: boolean
11+
}
12+
13+
export const DeleteDialog: React.FC<React.PropsWithChildren<DeleteDialogProps>> = ({
14+
isOpen,
15+
onCancel,
16+
onConfirm,
17+
title,
18+
description,
19+
confirmLoading,
20+
}) => (
21+
<ConfirmDialog
22+
type="delete"
23+
hideCancel={false}
24+
open={isOpen}
25+
title={title}
26+
onConfirm={onConfirm}
27+
onClose={onCancel}
28+
description={description}
29+
confirmLoading={confirmLoading}
30+
/>
31+
)

site/src/components/ResetPasswordDialog/ResetPasswordDialog.stories.tsx renamed to site/src/components/Dialogs/ResetPasswordDialog/ResetPasswordDialog.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { Story } from "@storybook/react"
2-
import { MockUser } from "../../testHelpers/renderHelpers"
2+
import { MockUser } from "../../../testHelpers/renderHelpers"
33
import { ResetPasswordDialog, ResetPasswordDialogProps } from "./ResetPasswordDialog"
44

55
export default {
6-
title: "components/ResetPasswordDialog",
6+
title: "components/Dialogs/ResetPasswordDialog",
77
component: ResetPasswordDialog,
88
argTypes: {
99
onClose: { action: "onClose" },

site/src/components/ResetPasswordDialog/ResetPasswordDialog.tsx renamed to site/src/components/Dialogs/ResetPasswordDialog/ResetPasswordDialog.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import DialogContentText from "@material-ui/core/DialogContentText"
22
import { makeStyles } from "@material-ui/core/styles"
33
import { FC } from "react"
4-
import * as TypesGen from "../../api/typesGenerated"
5-
import { CodeExample } from "../CodeExample/CodeExample"
4+
import * as TypesGen from "../../../api/typesGenerated"
5+
import { CodeExample } from "../../CodeExample/CodeExample"
66
import { ConfirmDialog } from "../ConfirmDialog/ConfirmDialog"
77

88
export interface ResetPasswordDialogProps {

0 commit comments

Comments
 (0)