From 3feff2a3672bd9f19e74f1ff284a4c015557a5b6 Mon Sep 17 00:00:00 2001 From: Evert Prants Date: Wed, 31 Aug 2022 19:24:45 +0300 Subject: [PATCH] some wild stuff, modals, dropdowns, forms etc --- components/OAuth2Page/OAuth2Page.module.scss | 6 + components/OAuth2Page/OAuth2Page.tsx | 162 +++++++++++++++++- .../common/Dropdown/Dropdown.module.scss | 77 +++++++++ components/common/Dropdown/Dropdown.tsx | 45 +++++ components/common/Form/Form.module.scss | 20 +++ .../common/Form/FormControl/FormControl.tsx | 20 +++ .../common/Form/FormWrapper/FormWrapper.tsx | 5 + .../common/Modal/Modal/Modal.module.scss | 3 + components/common/Modal/Modal/Modal.tsx | 15 +- .../common/Modal/ModalBody/ModalBody.tsx | 6 +- .../common/Modal/ModalFooter/ModalFooter.tsx | 2 +- .../common/Modal/ModalHeader/ModalHeader.tsx | 2 +- .../common/Modal/ModalRoot/ModalRoot.tsx | 47 +++-- .../common/Modal/services/ModalService.ts | 11 +- lib/hooks/useForm.ts | 24 +++ lib/types/modal.interface.ts | 24 ++- 16 files changed, 422 insertions(+), 47 deletions(-) create mode 100644 components/common/Dropdown/Dropdown.module.scss create mode 100644 components/common/Dropdown/Dropdown.tsx create mode 100644 components/common/Form/Form.module.scss create mode 100644 components/common/Form/FormControl/FormControl.tsx create mode 100644 components/common/Form/FormWrapper/FormWrapper.tsx create mode 100644 lib/hooks/useForm.ts diff --git a/components/OAuth2Page/OAuth2Page.module.scss b/components/OAuth2Page/OAuth2Page.module.scss index 7679088..6101d50 100644 --- a/components/OAuth2Page/OAuth2Page.module.scss +++ b/components/OAuth2Page/OAuth2Page.module.scss @@ -6,6 +6,11 @@ padding: 0.5rem; box-shadow: 0 0 8px rgba(0, 0, 0, 0.25); + .titleWrap { + display: flex; + justify-content: space-between; + } + .pictureWrapper { overflow: hidden; } @@ -13,6 +18,7 @@ .clientInfo { display: flex; flex-direction: column; + flex-grow: 1; h2 { padding: 0; diff --git a/components/OAuth2Page/OAuth2Page.tsx b/components/OAuth2Page/OAuth2Page.tsx index b8d16a9..17d3221 100644 --- a/components/OAuth2Page/OAuth2Page.tsx +++ b/components/OAuth2Page/OAuth2Page.tsx @@ -1,12 +1,16 @@ import useSWR from 'swr'; import Image from 'next/image'; -import { OAuth2ClientListItem } from '../../lib/types/oauth2-client.interface'; +import { + OAuth2ClientListItem, + OAuth2ClientURL, + OAuth2ClientURLType, +} from '../../lib/types/oauth2-client.interface'; import { PaginatedResponse } from '../../lib/types/paginated-response.interface'; import { Paginator } from '../common/Paginator/Paginator'; import styles from './OAuth2Page.module.scss'; import { UPLOADS_URL } from '../../lib/constants'; import application from '../../public/application.png'; -import { useState } from 'react'; +import { ChangeEvent, useMemo, useRef, useState } from 'react'; import useUser from '../../lib/hooks/useUser'; import { Container } from '../common/Container/Container'; import { Header } from '../common/Header/Header'; @@ -15,18 +19,147 @@ import ModalHeader from '../common/Modal/ModalHeader/ModalHeader'; import ModalBody from '../common/Modal/ModalBody/ModalBody'; import ModalFooter from '../common/Modal/ModalFooter/ModalFooter'; import ModalService from '../common/Modal/services/ModalService'; +import { Dropdown } from '../common/Dropdown/Dropdown'; +import { ModalProps } from '../../lib/types/modal.interface'; +import { useForm } from '../../lib/hooks/useForm'; +import { FormWrapper } from '../common/Form/FormWrapper/FormWrapper'; +import { FormControl } from '../common/Form/FormControl/FormControl'; -const TestModal = ({ close }: { close: (...args: any[]) => void }) => { +const LINK_NAMES = { + redirect_uri: 'Redirect URI', + terms: 'Terms of Service', + privacy: 'Privacy Policy', + website: 'Website', +}; + +const LinkEdit = ({ + formData, + handleInputChange, + linkType, +}: { + formData: Partial; + handleInputChange: ( + e: ChangeEvent, + setValue?: any, + formField?: string + ) => void; + linkType: OAuth2ClientURLType; +}) => { + const formUrl = useMemo>( + () => (formData.urls || []).find(({ type }) => type === linkType) || {}, + [formData, linkType] + ); return ( - + + + { + if (!formUrl.type) { + formUrl.type = linkType; + (formData.urls as Partial[])?.push(formUrl); + } + formUrl.url = e.target.value; + handleInputChange(e, formData.urls, 'urls'); + }} + /> + + ); +}; + +const EditClientModal = ({ + close, + modalRef, + client, +}: ModalProps<{ client?: OAuth2ClientListItem }>) => { + const formRef = useRef(null); + + const { formData, handleInputChange, handleSubmit } = useForm< + Partial + >(client || {}, () => { + console.log(formData); + return false; + }); + + return ( + -

Test!

+

Edit OAuth2 Client

-

This is only a test

+ +
+ + + + + + +