Skip to content
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

disable buttons for renaming file/folder #1179

Merged
merged 3 commits into from
Jun 24, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
ExclamationCircleInverseSvg,
ZoomInSvg } from "@chainsafe/common-components"
import { makeStyles, createStyles, useDoubleClick, useThemeSwitcher } from "@chainsafe/common-theme"
import { Formik, Form } from "formik"
import { Form, FormikProvider, useFormik } from "formik"
import CustomModal from "../../../../Elements/CustomModal"
import { Trans } from "@lingui/macro"
import { useDrag, useDrop } from "react-dnd"
Expand Down Expand Up @@ -143,6 +143,19 @@ const FileSystemItem = ({
}: IFileSystemItemProps) => {
const { downloadFile, currentPath, handleUploadOnDrop, moveItems } = useFileBrowser()
const { cid, name, isFolder, content_type } = file
const formik = useFormik({
initialValues:{
fileName: name
},
validationSchema:renameSchema,
onSubmit:(values) => {
handleRename &&
handleRename(
file.cid,
values.fileName
)
}
})
let Icon
if (isFolder) {
Icon = FolderFilledSvg
Expand Down Expand Up @@ -408,19 +421,7 @@ const FileSystemItem = ({
active={editing === cid}
setActive={() => setEditing("")}
>
<Formik
initialValues={{
fileName: name
}}
validationSchema={renameSchema}
onSubmit={(values) => {
handleRename &&
handleRename(
file.cid,
values.fileName
)
}}
>
<FormikProvider value={formik}>
<Form className={classes.renameModal}>
<Typography
className={classes.renameHeader}
Expand Down Expand Up @@ -453,12 +454,13 @@ const FileSystemItem = ({
size="medium"
type="submit"
className={classes.okButton}
disabled={!formik.dirty}
>
<Trans>Update</Trans>
</Button>
</footer>
</Form>
</Formik>
</FormikProvider>
</CustomModal>
<Typography>{name}</Typography>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { CSFTheme } from "../../../../../Themes/types"
import dayjs from "dayjs"
import { FileSystemItem } from "../../../../../Contexts/FilesContext"
import { ConnectDragPreview } from "react-dnd"
import { Form, Formik } from "formik"
import { Form, FormikProvider, useFormik } from "formik"

const useStyles = makeStyles(({ breakpoints, constants, palette }: CSFTheme) => {
const desktopGridSettings = "50px 69px 3fr 190px 100px 45px !important"
Expand Down Expand Up @@ -143,6 +143,19 @@ const FileSystemTableItem = React.forwardRef(
const classes = useStyles()
const { name, cid, created_at, size } = file
const { desktop } = useThemeSwitcher()
const formik = useFormik({
initialValues:{
fileName: name
},
validationSchema:renameSchema,
onSubmit:(values) => {
handleRename &&
handleRename(
file.cid,
values.fileName
)
}
})

return (
<TableRow
Expand Down Expand Up @@ -177,19 +190,7 @@ const FileSystemTableItem = React.forwardRef(
onClick={(e) => !editing && onFolderOrFileClicks(e)}
>
{editing === cid && desktop ? (
<Formik
initialValues={{
fileName: name
}}
validationSchema={renameSchema}
onSubmit={(values) => {
handleRename &&
handleRename(
file.cid,
values.fileName
)
}}
>
<FormikProvider value={formik}>
<Form
className={classes.desktopRename}
data-cy='rename-form'
Expand All @@ -215,11 +216,12 @@ const FileSystemTableItem = React.forwardRef(
variant="dashed"
size="small"
type="submit"
disabled={!formik.dirty}
>
<CheckSvg />
</Button>
</Form>
</Formik>
</FormikProvider>
) : (
<Typography>{name}</Typography>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from "@chainsafe/common-components"
import dayjs from "dayjs"
import { ConnectDragPreview } from "react-dnd"
import { Form, Formik } from "formik"
import { Form, FormikProvider, useFormik } from "formik"
import { CSSTheme } from "../../../Themes/types"
import { FileSystemItem } from "../../../Contexts/StorageContext"

Expand Down Expand Up @@ -143,6 +143,19 @@ const FileSystemTableItem = React.forwardRef(
const classes = useStyles()
const { name, cid, created_at, size } = file
const { desktop } = useThemeSwitcher()
const formik = useFormik({
initialValues: {
fileName: name
},
validationSchema: renameSchema,
onSubmit: (values) => {
handleRename &&
handleRename(
file.cid,
values.fileName
)
}
})

return (
<TableRow
Expand Down Expand Up @@ -177,19 +190,7 @@ const FileSystemTableItem = React.forwardRef(
onClick={(e) => !editing && onFolderOrFileClicks(e)}
>
{editing === cid && desktop ? (
<Formik
initialValues={{
fileName: name
}}
validationSchema={renameSchema}
onSubmit={(values) => {
handleRename &&
handleRename(
file.cid,
values.fileName
)
}}
>
<FormikProvider value={formik}>
<Form
className={classes.desktopRename}
data-cy='rename-form'
Expand All @@ -214,11 +215,12 @@ const FileSystemTableItem = React.forwardRef(
variant="dashed"
size="small"
type="submit"
disabled={!formik.dirty}
>
<CheckSvg />
</Button>
</Form>
</Formik>
</FormikProvider>
) : (
<Typography>{name}</Typography>
)}
Expand Down