diff --git a/src/pages/AddWorkspace/clone-wiki-done-button.tsx b/src/pages/AddWorkspace/CloneWikiDoneButton.tsx similarity index 81% rename from src/pages/AddWorkspace/clone-wiki-done-button.tsx rename to src/pages/AddWorkspace/CloneWikiDoneButton.tsx index b335e492..1440c520 100644 --- a/src/pages/AddWorkspace/clone-wiki-done-button.tsx +++ b/src/pages/AddWorkspace/CloneWikiDoneButton.tsx @@ -3,56 +3,18 @@ import React from 'react'; import styled from 'styled-components'; import { Trans, useTranslation } from 'react-i18next'; -import Typography from '@material-ui/core/Typography'; -import Button from '@material-ui/core/Button'; -import LinearProgress from '@material-ui/core/LinearProgress'; -import Snackbar from '@material-ui/core/Snackbar'; +import { Typography, Button, LinearProgress, Snackbar } from '@material-ui/core'; import Alert from '@material-ui/lab/Alert'; -import type { IAuthingUserInfo } from '@services/types'; - import useWikiCreationMessage from './use-wiki-creation-message'; +import type { IWikiWorkspaceFormProps } from './useForm'; const CloseButton = styled(Button)` white-space: nowrap; width: 100%; `; -interface OwnProps { - isCreateMainWorkspace: boolean; - wikiPort: number; - mainWikiToLink: { name: string; port: number }; - githubWikiUrl: string; - wikiFolderName: string; - parentFolderLocation: string; - tagName: string; - userInfo: IAuthingUserInfo; -} -interface DispatchProps { - updateForm: (Object) => void; - setWikiCreationMessage: (string) => void; - save: () => void; -} -interface StateProps { - wikiCreationMessage: string; -} - -type Props = OwnProps & DispatchProps & StateProps; - -export function CloneWikiDoneButton({ - isCreateMainWorkspace, - wikiPort, - mainWikiToLink, - githubWikiUrl, - wikiFolderName, - parentFolderLocation, - updateForm, - setWikiCreationMessage, - wikiCreationMessage, - tagName, - save, - userInfo, -}: Props): JSX.Element { +export function CloneWikiDoneButton({ form }: IWikiWorkspaceFormProps): JSX.Element { const wikiFolderLocation = `${parentFolderLocation}/${wikiFolderName}`; const port = isCreateMainWorkspace ? wikiPort : mainWikiToLink.port; diff --git a/src/pages/AddWorkspace/description-and-mode-switch.tsx b/src/pages/AddWorkspace/Description.tsx similarity index 65% rename from src/pages/AddWorkspace/description-and-mode-switch.tsx rename to src/pages/AddWorkspace/Description.tsx index c1d58a93..4b91a481 100644 --- a/src/pages/AddWorkspace/description-and-mode-switch.tsx +++ b/src/pages/AddWorkspace/Description.tsx @@ -1,4 +1,3 @@ -import type { ComponentType } from 'react'; import React from 'react'; import styled from 'styled-components'; import { useTranslation } from 'react-i18next'; @@ -8,22 +7,20 @@ import FormControlLabel from '@material-ui/core/FormControlLabel'; import Switch from '@material-ui/core/Switch'; import Typography from '@material-ui/core/Typography'; -const Container: ComponentType<{}> = styled(Paper)` +const Container = styled(Paper)` padding: 10px; `; interface Props { isCreateMainWorkspace: boolean; - // @ts-expect-error ts-migrate(7051) FIXME: Parameter has a name but no type. Did you mean 'ar... Remove this comment to see the full error message - isCreateMainWorkspaceSetter: (boolean) => void; + isCreateMainWorkspaceSetter: (is: boolean) => void; } -export default function Description({ isCreateMainWorkspace, isCreateMainWorkspaceSetter }: Props) { +export function Description({ isCreateMainWorkspace, isCreateMainWorkspaceSetter }: Props): JSX.Element { const { t } = useTranslation(); const label = isCreateMainWorkspace ? t('AddWorkspace.MainWorkspace') : t('AddWorkspace.SubWorkspace'); const description = isCreateMainWorkspace ? t('AddWorkspace.MainWorkspaceDescription') : t('AddWorkspace.SubWorkspaceDescription'); return ( - // @ts-expect-error ts-migrate(2322) FIXME: Type '{ children: Element[]; elevation: number; sq... Remove this comment to see the full error message isCreateMainWorkspaceSetter(event.target.checked)} />} diff --git a/src/pages/AddWorkspace/existed-wiki-done-button.tsx b/src/pages/AddWorkspace/ExistedWikiDoneButton.tsx similarity index 78% rename from src/pages/AddWorkspace/existed-wiki-done-button.tsx rename to src/pages/AddWorkspace/ExistedWikiDoneButton.tsx index f579567f..93910638 100644 --- a/src/pages/AddWorkspace/existed-wiki-done-button.tsx +++ b/src/pages/AddWorkspace/ExistedWikiDoneButton.tsx @@ -1,56 +1,19 @@ import React from 'react'; import styled from 'styled-components'; -import { connect } from 'react-redux'; -import { bindActionCreators } from 'redux'; import { Trans, useTranslation } from 'react-i18next'; -import Typography from '@material-ui/core/Typography'; -import Button from '@material-ui/core/Button'; -import LinearProgress from '@material-ui/core/LinearProgress'; -import Snackbar from '@material-ui/core/Snackbar'; +import { Typography, Button, LinearProgress, Snackbar } from '@material-ui/core'; import Alert from '@material-ui/lab/Alert'; -import type { IAuthingUserInfo } from '@services/types'; import useWikiCreationMessage from './use-wiki-creation-message'; +import type { IWikiWorkspaceFormProps } from './useForm'; const CloseButton = styled(Button)` white-space: nowrap; width: 100%; `; -interface OwnProps { - isCreateMainWorkspace: boolean; - wikiPort: number; - mainWikiToLink: { name: string; port: number }; - githubWikiUrl: string; - existedFolderLocation: string; - tagName: string; - userInfo: IAuthingUserInfo; -} -interface DispatchProps { - updateForm: (Object) => void; - setWikiCreationMessage: (string) => void; - save: () => void; -} -interface StateProps { - wikiCreationMessage: string; -} - -type Props = OwnProps & DispatchProps & StateProps; - -function DoneButton({ - isCreateMainWorkspace, - wikiPort, - mainWikiToLink, - githubWikiUrl, - existedFolderLocation, - updateForm, - setWikiCreationMessage, - wikiCreationMessage, - tagName, - save, - userInfo, -}: Props) { +export function ExistedWikiDoneButton({ form }: IWikiWorkspaceFormProps): JSX.Element{ const port = isCreateMainWorkspace ? wikiPort : mainWikiToLink.port; const workspaceFormData = { name: existedFolderLocation, @@ -160,9 +123,3 @@ function DoneButton({ ); } - -const mapStateToProps = (state: any) => ({ - wikiCreationMessage: state.dialogAddWorkspace.wikiCreationMessage, -}); - -export default connect(mapStateToProps, (dispatch) => bindActionCreators(actions, dispatch))(DoneButton); diff --git a/src/pages/AddWorkspace/existed-wiki-path-form.tsx b/src/pages/AddWorkspace/ExistedWikiForm.tsx similarity index 56% rename from src/pages/AddWorkspace/existed-wiki-path-form.tsx rename to src/pages/AddWorkspace/ExistedWikiForm.tsx index f91e6938..ffa8fd96 100644 --- a/src/pages/AddWorkspace/existed-wiki-path-form.tsx +++ b/src/pages/AddWorkspace/ExistedWikiForm.tsx @@ -4,17 +4,12 @@ import styled from 'styled-components'; import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; import { useTranslation } from 'react-i18next'; -import Paper from '@material-ui/core/Paper'; -import Typography from '@material-ui/core/Typography'; -import Button from '@material-ui/core/Button'; -import TextField from '@material-ui/core/TextField'; -import InputLabel from '@material-ui/core/InputLabel'; -import FormHelperText from '@material-ui/core/FormHelperText'; -import Select from '@material-ui/core/Select'; -import MenuItem from '@material-ui/core/MenuItem'; -import FolderIcon from '@material-ui/icons/Folder'; -import Autocomplete from '@material-ui/lab/Autocomplete'; -const CreateContainer: ComponentType<{}> = styled(Paper)` +import { Paper, Typography, Button, TextField, InputLabel, FormHelperText, Select, MenuItem } from '@material-ui/core'; +import { Folder as FolderIcon } from '@material-ui/icons'; +import { Autocomplete } from '@material-ui/lab'; +import type { IWikiWorkspaceFormProps } from './useForm'; + +const CreateContainer = styled(Paper)` margin-top: 5px; `; const LocationPickerContainer = styled.div` @@ -32,53 +27,7 @@ const SoftLinkToMainWikiSelect = styled(Select)` const SoftLinkToMainWikiSelectInputLabel = styled(InputLabel)` margin-top: 5px; `; -interface OwnProps { - wikiCreationMessage: string; - // @ts-expect-error ts-migrate(7051) FIXME: Parameter has a name but no type. Did you mean 'ar... Remove this comment to see the full error message - existedFolderLocationSetter: (string) => void; - wikiFolderName: string; - // @ts-expect-error ts-migrate(7051) FIXME: Parameter has a name but no type. Did you mean 'ar... Remove this comment to see the full error message - wikiFolderNameSetter: (string) => void; - tagName: string; - // @ts-expect-error ts-migrate(7051) FIXME: Parameter has a name but no type. Did you mean 'ar... Remove this comment to see the full error message - tagNameSetter: (string) => void; - mainWikiToLink: Object; - // @ts-expect-error ts-migrate(7051) FIXME: Parameter has a name but no type. Did you mean 'ar... Remove this comment to see the full error message - mainWikiToLinkSetter: (Object) => void; - existedFolderLocation: string; - wikiPort: number; - // @ts-expect-error ts-migrate(7051) FIXME: Parameter has a name but no type. Did you mean 'ar... Remove this comment to see the full error message - wikiPortSetter: (number) => void; - fileSystemPaths: Array<{ - tagName: string; - folderName: string; - }>; - isCreateMainWorkspace: boolean; -} -interface DispatchProps { - // @ts-expect-error ts-migrate(7051) FIXME: Parameter has a name but no type. Did you mean 'ar... Remove this comment to see the full error message - setWikiCreationMessage: (string) => void; -} -interface StateProps { - wikiCreationMessage: string; -} -type Props = OwnProps & DispatchProps & StateProps; -function WikiPathForm({ - setWikiCreationMessage, - wikiCreationMessage = '', - existedFolderLocation, - existedFolderLocationSetter, - tagName, - tagNameSetter, - wikiFolderName, - wikiFolderNameSetter, - mainWikiToLink, - mainWikiToLinkSetter, - wikiPort, - wikiPortSetter, - fileSystemPaths, - isCreateMainWorkspace, -}: Props) { +export function ExistedWikiForm({ form }: IWikiWorkspaceFormProps): JSX.Element{ const [workspaces, workspacesSetter] = useState({}); useEffect(() => { void (async () => { @@ -88,7 +37,6 @@ function WikiPathForm({ const hasError = wikiCreationMessage.startsWith('Error'); const { t } = useTranslation(); return ( - // @ts-expect-error ts-migrate(2322) FIXME: Type '{ children: (false | Element)[]; elevation: ... Remove this comment to see the full error message mainWikiToLinkSetter(event.target.value)}> {Object.keys(workspaces).map((workspaceID) => ( - // @ts-expect-error ts-migrate(7053) FIXME: Element implicitly has an 'any' type because expre... Remove this comment to see the full error message - {/* @ts-expect-error ts-migrate(7053) FIXME: Element implicitly has an 'any' type because expre... Remove this comment to see the full error message */} {workspaces[workspaceID].name} ))} @@ -173,9 +119,4 @@ function WikiPathForm({ )} ); -} -const mapStateToProps = (state: any) => ({ - wikiCreationMessage: state.dialogAddWorkspace.wikiCreationMessage, -}); -// @ts-expect-error ts-migrate(2558) FIXME: Expected 5 type arguments, but got 6. -export default connect(mapStateToProps, (dispatch) => bindActionCreators(actions, dispatch))(WikiPathForm); +} \ No newline at end of file diff --git a/src/pages/AddWorkspace/new-wiki-done-button.tsx b/src/pages/AddWorkspace/NewWikiDoneButton.tsx similarity index 78% rename from src/pages/AddWorkspace/new-wiki-done-button.tsx rename to src/pages/AddWorkspace/NewWikiDoneButton.tsx index 3ee44be9..bf6b1eda 100644 --- a/src/pages/AddWorkspace/new-wiki-done-button.tsx +++ b/src/pages/AddWorkspace/NewWikiDoneButton.tsx @@ -1,63 +1,21 @@ import React from 'react'; import styled from 'styled-components'; -import { connect } from 'react-redux'; -import { bindActionCreators } from 'redux'; import { Trans, useTranslation } from 'react-i18next'; -import Typography from '@material-ui/core/Typography'; -import Button from '@material-ui/core/Button'; -import LinearProgress from '@material-ui/core/LinearProgress'; -import Snackbar from '@material-ui/core/Snackbar'; +import { Typography, Button, LinearProgress, Snackbar } from '@material-ui/core'; import Alert from '@material-ui/lab/Alert'; -import type { IAuthingUserInfo } from '@services/types'; - import useWikiCreationMessage from './use-wiki-creation-message'; +import type { IWikiWorkspaceFormProps } from './useForm'; const CloseButton = styled(Button)` white-space: nowrap; width: 100%; `; -interface OwnProps { - isCreateMainWorkspace: boolean; - wikiPort: number; - mainWikiToLink: { name: string; port: number }; - githubWikiUrl: string; - wikiFolderName: string; - parentFolderLocation: string; - tagName: string; - userInfo: IAuthingUserInfo; -} -interface DispatchProps { - updateForm: (Object) => void; - setWikiCreationMessage: (string) => void; - save: () => void; -} - -interface StateProps { - wikiCreationMessage: string; -} - -type Props = OwnProps & DispatchProps & StateProps; - -function NewWikiDoneButton({ - isCreateMainWorkspace, - wikiPort, - mainWikiToLink, - githubWikiUrl, - wikiFolderName, - parentFolderLocation, - updateForm, - setWikiCreationMessage, - wikiCreationMessage, - tagName, - save, - userInfo, -}: Props): JSX.Element { +export function NewWikiDoneButton({ form }: IWikiWorkspaceFormProps): JSX.Element { const wikiFolderLocation = `${parentFolderLocation}/${wikiFolderName}`; - const port = isCreateMainWorkspace ? wikiPort : mainWikiToLink.port; const workspaceFormData = { name: wikiFolderLocation, isSubWiki: !isCreateMainWorkspace, @@ -186,9 +144,3 @@ function NewWikiDoneButton({ ); } - -const mapStateToProps = (state: any) => ({ - wikiCreationMessage: state.dialogAddWorkspace.wikiCreationMessage, -}); - -export default connect(mapStateToProps, (dispatch) => bindActionCreators(actions, dispatch))(NewWikiDoneButton); diff --git a/src/pages/AddWorkspace/new-wiki-path-form.tsx b/src/pages/AddWorkspace/NewWikiForm.tsx similarity index 56% rename from src/pages/AddWorkspace/new-wiki-path-form.tsx rename to src/pages/AddWorkspace/NewWikiForm.tsx index 4fafc93a..4e9f6fd8 100644 --- a/src/pages/AddWorkspace/new-wiki-path-form.tsx +++ b/src/pages/AddWorkspace/NewWikiForm.tsx @@ -1,19 +1,10 @@ -import type { ComponentType } from 'react'; -import React, { useState, useEffect } from 'react'; +import React, { useState, useEffect, ComponentType } from 'react'; import styled from 'styled-components'; -import { connect } from 'react-redux'; -import { bindActionCreators } from 'redux'; import { useTranslation } from 'react-i18next'; -import Paper from '@material-ui/core/Paper'; -import Typography from '@material-ui/core/Typography'; -import Button from '@material-ui/core/Button'; -import TextField from '@material-ui/core/TextField'; -import InputLabel from '@material-ui/core/InputLabel'; -import FormHelperText from '@material-ui/core/FormHelperText'; -import Select from '@material-ui/core/Select'; -import MenuItem from '@material-ui/core/MenuItem'; -import FolderIcon from '@material-ui/icons/Folder'; -import Autocomplete from '@material-ui/lab/Autocomplete'; +import { Paper, Typography, Button, TextField, InputLabel, FormHelperText, Select, MenuItem, Autocomplete } from '@material-ui/core'; +import { Folder as FolderIcon } from '@material-ui/icons'; +import type { IWikiWorkspaceFormProps } from './useForm'; + const CreateContainer: ComponentType<{}> = styled(Paper)` margin-top: 5px; `; @@ -32,52 +23,8 @@ const SoftLinkToMainWikiSelect = styled(Select)` const SoftLinkToMainWikiSelectInputLabel = styled(InputLabel)` margin-top: 5px; `; -interface OwnProps { - // @ts-expect-error ts-migrate(7051) FIXME: Parameter has a name but no type. Did you mean 'ar... Remove this comment to see the full error message - parentFolderLocationSetter: (string) => void; - wikiFolderName: string; - // @ts-expect-error ts-migrate(7051) FIXME: Parameter has a name but no type. Did you mean 'ar... Remove this comment to see the full error message - wikiFolderNameSetter: (string) => void; - tagName: string; - // @ts-expect-error ts-migrate(7051) FIXME: Parameter has a name but no type. Did you mean 'ar... Remove this comment to see the full error message - tagNameSetter: (string) => void; - mainWikiToLink: Object; - // @ts-expect-error ts-migrate(7051) FIXME: Parameter has a name but no type. Did you mean 'ar... Remove this comment to see the full error message - mainWikiToLinkSetter: (Object) => void; - parentFolderLocation: string; - wikiPort: number; - // @ts-expect-error ts-migrate(7051) FIXME: Parameter has a name but no type. Did you mean 'ar... Remove this comment to see the full error message - wikiPortSetter: (number) => void; - fileSystemPaths: Array<{ - tagName: string; - folderName: string; - }>; - isCreateMainWorkspace: boolean; -} -interface DispatchProps { - // @ts-expect-error ts-migrate(7051) FIXME: Parameter has a name but no type. Did you mean 'ar... Remove this comment to see the full error message - setWikiCreationMessage: (string) => void; -} -interface StateProps { - wikiCreationMessage: string; -} -type Props = OwnProps & DispatchProps & StateProps; -function NewWikiPathForm({ - setWikiCreationMessage, - wikiCreationMessage = '', - parentFolderLocation, - parentFolderLocationSetter, - tagName, - tagNameSetter, - wikiFolderName, - wikiFolderNameSetter, - mainWikiToLink, - mainWikiToLinkSetter, - wikiPort, - wikiPortSetter, - fileSystemPaths, - isCreateMainWorkspace, -}: Props) { + +export function NewWikiForm({ form }: IWikiWorkspaceFormProps): JSX.Element { const [workspaces, workspacesSetter] = useState({}); useEffect(() => { void (async () => { @@ -87,7 +34,6 @@ function NewWikiPathForm({ const hasError = wikiCreationMessage.startsWith('Error'); const { t } = useTranslation(); return ( - // @ts-expect-error ts-migrate(2322) FIXME: Type '{ children: (false | Element)[]; elevation: ... Remove this comment to see the full error message mainWikiToLinkSetter(event.target.value)}> {Object.keys(workspaces).map((workspaceID) => ( - // @ts-expect-error ts-migrate(7053) FIXME: Element implicitly has an 'any' type because expre... Remove this comment to see the full error message - {/* @ts-expect-error ts-migrate(7053) FIXME: Element implicitly has an 'any' type because expre... Remove this comment to see the full error message */} {workspaces[workspaceID].name} ))} @@ -183,14 +127,3 @@ function NewWikiPathForm({ ); } -// @ts-expect-error ts-migrate(2558) FIXME: Expected 5 type arguments, but got 6. -export default connect( - ( - state: any, - ): { - wikiCreationMessage: string; - } => ({ - wikiCreationMessage: state.dialogAddWorkspace.wikiCreationMessage, - }), - (dispatch) => bindActionCreators(actions, dispatch), -)(NewWikiPathForm); diff --git a/src/pages/AddWorkspace/index.tsx b/src/pages/AddWorkspace/index.tsx index 9f62b384..9dcad89f 100644 --- a/src/pages/AddWorkspace/index.tsx +++ b/src/pages/AddWorkspace/index.tsx @@ -1,16 +1,16 @@ -import React, { useState, useEffect } from 'react'; +import React, { useState } from 'react'; import styled from 'styled-components'; import { GraphQLClient, ClientContext } from 'graphql-hooks'; import { GITHUB_GRAPHQL_API } from '../../constants/auth'; -import Description from './description-and-mode-switch'; +import { Description } from './Description'; -import NewWikiDoneButton from './new-wiki-done-button'; -import NewWikiPathForm from './new-wiki-path-form'; -import ExistedWikiPathForm from './existed-wiki-path-form'; -import ExistedWikiDoneButton from './existed-wiki-done-button'; -import CloneWikiDoneButton from './clone-wiki-done-button'; +import { NewWikiForm } from './NewWikiForm'; +import { NewWikiDoneButton } from './NewWikiDoneButton'; +import { ExistedWikiForm } from './ExistedWikiForm'; +import { ExistedWikiDoneButton } from './ExistedWikiDoneButton'; +import { CloneWikiDoneButton } from './CloneWikiDoneButton'; import { TabBar, CreateWorkspaceTabs } from './TabBar'; import { useIsCreateMainWorkspace, useWikiWorkspaceForm } from './useForm'; @@ -41,7 +41,7 @@ export default function AddWorkspace(): JSX.Element { {currentTab === 'CreateNewWiki' && ( - + diff --git a/src/pages/AddWorkspace/useForm.ts b/src/pages/AddWorkspace/useForm.ts index f69885d3..077d66a9 100644 --- a/src/pages/AddWorkspace/useForm.ts +++ b/src/pages/AddWorkspace/useForm.ts @@ -13,6 +13,10 @@ export function useIsCreateMainWorkspace(): [boolean, React.Dispatch; +export interface IWikiWorkspaceFormProps { + form: IWikiWorkspaceForm; +} export function useWikiWorkspaceForm() { const [wikiPort, wikiPortSetter] = useState(5212); useEffect(() => {