From 27410bc32b9cd1f5832d53b4a28fff8486355207 Mon Sep 17 00:00:00 2001 From: Sabir Hassan Date: Mon, 18 Jul 2022 22:37:32 +0500 Subject: [PATCH] chore: add file path input modal --- web/src/components/filePathInputModal.tsx | 70 +++++++++++++++++++++++ web/src/components/modal.tsx | 4 +- 2 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 web/src/components/filePathInputModal.tsx diff --git a/web/src/components/filePathInputModal.tsx b/web/src/components/filePathInputModal.tsx new file mode 100644 index 0000000..a75dedc --- /dev/null +++ b/web/src/components/filePathInputModal.tsx @@ -0,0 +1,70 @@ +import React, { useState } from 'react' + +import { Button, DialogActions, DialogContent, TextField } from '@mui/material' + +import { BootstrapDialogTitle } from './dialogTitle' +import { BootstrapDialog } from './modal' + +type FilePathInputModalProps = { + open: boolean + setOpen: React.Dispatch> + saveFile: (filePath: string) => void +} + +const FilePathInputModal = ({ + open, + setOpen, + saveFile +}: FilePathInputModalProps) => { + const [filePath, setFilePath] = useState('') + const [hasError, setHasError] = useState(false) + const [errorText, setErrorText] = useState('') + + const handleChange = (event: React.ChangeEvent) => { + const value = event.target.value + const regex = /\.(exe|sh|htaccess)$/i + if (regex.test(value)) { + setHasError(true) + setErrorText('can not save file with extensions [exe, sh, htaccess]') + } else { + setHasError(false) + setErrorText('') + } + setFilePath(value) + } + + return ( + setOpen(false)} open={open}> + + Save File + + + + + + + + + + ) +} + +export default FilePathInputModal diff --git a/web/src/components/modal.tsx b/web/src/components/modal.tsx index 223bd9a..081d480 100644 --- a/web/src/components/modal.tsx +++ b/web/src/components/modal.tsx @@ -5,7 +5,7 @@ import { styled } from '@mui/material/styles' import { BootstrapDialogTitle } from './dialogTitle' -const BootstrapDialog = styled(Dialog)(({ theme }) => ({ +export const BootstrapDialog = styled(Dialog)(({ theme }) => ({ '& .MuiDialogContent-root': { padding: theme.spacing(2) }, @@ -14,7 +14,7 @@ const BootstrapDialog = styled(Dialog)(({ theme }) => ({ } })) -export interface ModalProps { +type ModalProps = { open: boolean setOpen: React.Dispatch> title: string