-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): create the form to create a new folder
- Loading branch information
1 parent
25efd14
commit 18ebe93
Showing
16 changed files
with
181 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/ui/src/common/folders/empty.tsx → ...ui/src/common/directory/folders/empty.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
packages/ui/src/common/folders/folder.tsx → ...i/src/common/directory/folders/folder.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
packages/ui/src/common/directory/folders/new/new-folder-container.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import { Dialog, Transition } from '@headlessui/react'; | ||
import { yupResolver } from '@hookform/resolvers/yup'; | ||
import { Fragment, useRef } from 'react'; | ||
import { FormProvider, useForm } from 'react-hook-form'; | ||
import * as yup from 'yup'; | ||
|
||
import Button from '../../../../forms/button'; | ||
import TextInput from '../../../../forms/text-input'; | ||
import { FOLDER_NAME_REGEX, FORM_ERRORS } from '../../../../utils/constants'; | ||
|
||
type Props = { | ||
closeModal: () => void; | ||
}; | ||
|
||
const MIN_NAME_LENGTH = 1; | ||
const MAX_NAME_LENGTH = 100; | ||
const formSchema = yup.object().shape({ | ||
name: yup | ||
.string() | ||
.required(FORM_ERRORS.fieldRequired) | ||
.min(MIN_NAME_LENGTH, FORM_ERRORS.minCharacters(MIN_NAME_LENGTH)) | ||
.max(MAX_NAME_LENGTH, FORM_ERRORS.minCharacters(MAX_NAME_LENGTH)) | ||
.matches(FOLDER_NAME_REGEX, { excludeEmptyString: false, message: FORM_ERRORS.folderNameInvalid }), | ||
}); | ||
|
||
type FormValues = { name?: string }; | ||
|
||
const NewFolderContainer = ({ closeModal }: Props) => { | ||
const cancelButtonRef = useRef(null); | ||
|
||
const formMethods = useForm<FormValues>({ | ||
defaultValues: { | ||
name: 'New folder', | ||
}, | ||
resolver: yupResolver(formSchema), | ||
}); | ||
|
||
const submitCreateFolder = (values: FormValues) => { | ||
console.log(values); | ||
}; | ||
|
||
return ( | ||
<Transition.Root show as={Fragment}> | ||
<Dialog as="div" className="relative z-10" initialFocus={cancelButtonRef} onClose={closeModal}> | ||
<Transition.Child | ||
as={Fragment} | ||
enter="ease-out duration-300" | ||
enterFrom="opacity-0" | ||
enterTo="opacity-100" | ||
leave="ease-in duration-200" | ||
leaveFrom="opacity-100" | ||
leaveTo="opacity-0" | ||
> | ||
<div className="fixed inset-0 bg-gray-500 bg-opacity-75 transition-opacity" /> | ||
</Transition.Child> | ||
|
||
<div className="fixed z-10 inset-0 overflow-y-auto"> | ||
<div className="flex items-end sm:items-center justify-center min-h-full p-4 text-center sm:p-0"> | ||
<Transition.Child | ||
as={Fragment} | ||
enter="ease-out duration-300" | ||
enterFrom="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95" | ||
enterTo="opacity-100 translate-y-0 sm:scale-100" | ||
leave="ease-in duration-200" | ||
leaveFrom="opacity-100 translate-y-0 sm:scale-100" | ||
leaveTo="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95" | ||
> | ||
<Dialog.Panel className="relative bg-white rounded-lg px-4 pt-5 pb-4 text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:max-w-lg sm:w-full sm:p-6"> | ||
<div className="sm:flex sm:items-start"> | ||
<div className="mt-3 text-center sm:mt-0 sm:text-left w-full"> | ||
<Dialog.Title as="h3" className="text-lg leading-6 font-medium text-gray-900"> | ||
Create a new folder | ||
</Dialog.Title> | ||
<div className="mt-2"> | ||
<FormProvider {...formMethods}> | ||
<TextInput className="mt-6 w-full" type="text" name="name" /> | ||
</FormProvider> | ||
</div> | ||
</div> | ||
</div> | ||
<div className="mt-5 sm:mt-4 sm:flex sm:flex-row-reverse"> | ||
<Button | ||
className="sm:w-auto sm:ml-3 sm:text-sm mt-0 rounded-md" | ||
onClick={formMethods.handleSubmit(submitCreateFolder)} | ||
> | ||
Create | ||
</Button> | ||
<button | ||
type="button" | ||
className="mt-3 w-full inline-flex justify-center rounded-md border border-gray-300 shadow-sm px-4 py-2 bg-white text-base font-medium text-gray-700 hover:bg-gray-50 sm:mt-0 sm:w-auto sm:text-sm" | ||
onClick={closeModal} | ||
ref={cancelButtonRef} | ||
> | ||
Cancel | ||
</button> | ||
</div> | ||
</Dialog.Panel> | ||
</Transition.Child> | ||
</div> | ||
</div> | ||
</Dialog> | ||
</Transition.Root> | ||
); | ||
}; | ||
|
||
export default NewFolderContainer; |
2 changes: 1 addition & 1 deletion
2
packages/ui/src/common/folders/index.tsx → packages/ui/src/common/directory/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import Directory from './directory'; | ||
import EmptyFolder from './empty'; | ||
import EmptyFolder from './folders/empty'; | ||
|
||
export default { Directory, Empty: EmptyFolder }; |
6 changes: 3 additions & 3 deletions
6
packages/ui/src/common/folders/snippet.tsx → ...src/common/directory/snippets/snippet.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import useBooleanState from './use-boolean-state'; | ||
|
||
export { useBooleanState }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { useCallback, useState } from 'react'; | ||
|
||
const useBooleanState = (initialState = false) => { | ||
const [boolean, setBoolean] = useState(initialState); | ||
|
||
const setToTrue = useCallback(() => setBoolean(true), []); | ||
|
||
const setToFalse = useCallback(() => setBoolean(false), []); | ||
|
||
return [boolean, setToTrue, setToFalse] as const; | ||
}; | ||
|
||
export default useBooleanState; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters