Kind of get account stuff working; IDE is throwing a fit right now

This commit is contained in:
Dane Everitt 2020-07-03 15:37:26 -07:00
parent 7cea5e630c
commit e8755ac598
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
7 changed files with 176 additions and 43 deletions

View file

@ -14,4 +14,22 @@ export default createGlobalStyle`
p { p {
${tw`text-neutral-200 leading-snug font-sans`}; ${tw`text-neutral-200 leading-snug font-sans`};
} }
form {
${tw`m-0`};
}
textarea, select, input, button, button:focus, button:focus-visible {
${tw`outline-none`};
}
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button {
-webkit-appearance: none !important;
margin: 0;
}
input[type=number] {
-moz-appearance: textfield !important;
}
`; `;

View file

@ -3,6 +3,8 @@ import { useStoreState } from 'easy-peasy';
import { ApplicationStore } from '@/state'; import { ApplicationStore } from '@/state';
import SetupTwoFactorModal from '@/components/dashboard/forms/SetupTwoFactorModal'; import SetupTwoFactorModal from '@/components/dashboard/forms/SetupTwoFactorModal';
import DisableTwoFactorModal from '@/components/dashboard/forms/DisableTwoFactorModal'; import DisableTwoFactorModal from '@/components/dashboard/forms/DisableTwoFactorModal';
import tw from 'twin.macro';
import Button from '@/components/elements/Button';
export default () => { export default () => {
const user = useStoreState((state: ApplicationStore) => state.user.data!); const user = useStoreState((state: ApplicationStore) => state.user.data!);
@ -17,38 +19,40 @@ export default () => {
onDismissed={() => setVisible(false)} onDismissed={() => setVisible(false)}
/> />
} }
<p className={'text-sm'}> <p css={tw`text-sm`}>
Two-factor authentication is currently enabled on your account. Two-factor authentication is currently enabled on your account.
</p> </p>
<div className={'mt-6'}> <div css={tw`mt-6`}>
<button <Button
color={'red'}
isSecondary
onClick={() => setVisible(true)} onClick={() => setVisible(true)}
className={'btn btn-red btn-secondary btn-sm'}
> >
Disable Disable
</button> </Button>
</div> </div>
</div> </div>
: :
<div> <div>
{visible && {visible &&
<SetupTwoFactorModal <SetupTwoFactorModal
appear={true} appear
visible={visible} visible={visible}
onDismissed={() => setVisible(false)} onDismissed={() => setVisible(false)}
/> />
} }
<p className={'text-sm'}> <p css={tw`text-sm`}>
You do not currently have two-factor authentication enabled on your account. Click You do not currently have two-factor authentication enabled on your account. Click
the button below to begin configuring it. the button below to begin configuring it.
</p> </p>
<div className={'mt-6'}> <div css={tw`mt-6`}>
<button <Button
color={'green'}
isSecondary
onClick={() => setVisible(true)} onClick={() => setVisible(true)}
className={'btn btn-green btn-secondary btn-sm'}
> >
Begin Setup Begin Setup
</button> </Button>
</div> </div>
</div> </div>
; ;

View file

@ -6,6 +6,8 @@ import SpinnerOverlay from '@/components/elements/SpinnerOverlay';
import Field from '@/components/elements/Field'; import Field from '@/components/elements/Field';
import { httpErrorToHuman } from '@/api/http'; import { httpErrorToHuman } from '@/api/http';
import { ApplicationStore } from '@/state'; import { ApplicationStore } from '@/state';
import tw from 'twin.macro';
import Button from '@/components/elements/Button';
interface Values { interface Values {
email: string; email: string;
@ -54,14 +56,14 @@ export default () => {
({ isSubmitting, isValid }) => ( ({ isSubmitting, isValid }) => (
<React.Fragment> <React.Fragment>
<SpinnerOverlay size={'large'} visible={isSubmitting}/> <SpinnerOverlay size={'large'} visible={isSubmitting}/>
<Form className={'m-0'}> <Form css={tw`m-0`}>
<Field <Field
id={'current_email'} id={'current_email'}
type={'email'} type={'email'}
name={'email'} name={'email'}
label={'Email'} label={'Email'}
/> />
<div className={'mt-6'}> <div css={tw`mt-6`}>
<Field <Field
id={'confirm_password'} id={'confirm_password'}
type={'password'} type={'password'}
@ -69,10 +71,10 @@ export default () => {
label={'Confirm Password'} label={'Confirm Password'}
/> />
</div> </div>
<div className={'mt-6'}> <div css={tw`mt-6`}>
<button className={'btn btn-sm btn-primary'} disabled={isSubmitting || !isValid}> <Button size={'small'} disabled={isSubmitting || !isValid}>
Update Email Update Email
</button> </Button>
</div> </div>
</Form> </Form>
</React.Fragment> </React.Fragment>

View file

@ -7,6 +7,8 @@ import SpinnerOverlay from '@/components/elements/SpinnerOverlay';
import updateAccountPassword from '@/api/account/updateAccountPassword'; import updateAccountPassword from '@/api/account/updateAccountPassword';
import { httpErrorToHuman } from '@/api/http'; import { httpErrorToHuman } from '@/api/http';
import { ApplicationStore } from '@/state'; import { ApplicationStore } from '@/state';
import tw from 'twin.macro';
import Button from '@/components/elements/Button';
interface Values { interface Values {
current: string; current: string;
@ -34,7 +36,6 @@ export default () => {
clearFlashes('account:password'); clearFlashes('account:password');
updateAccountPassword({ ...values }) updateAccountPassword({ ...values })
.then(() => { .then(() => {
// @ts-ignore
window.location = '/auth/login'; window.location = '/auth/login';
}) })
.catch(error => addFlash({ .catch(error => addFlash({
@ -57,14 +58,14 @@ export default () => {
({ isSubmitting, isValid }) => ( ({ isSubmitting, isValid }) => (
<React.Fragment> <React.Fragment>
<SpinnerOverlay size={'large'} visible={isSubmitting}/> <SpinnerOverlay size={'large'} visible={isSubmitting}/>
<Form className={'m-0'}> <Form css={tw`m-0`}>
<Field <Field
id={'current_password'} id={'current_password'}
type={'password'} type={'password'}
name={'current'} name={'current'}
label={'Current Password'} label={'Current Password'}
/> />
<div className={'mt-6'}> <div css={tw`mt-6`}>
<Field <Field
id={'new_password'} id={'new_password'}
type={'password'} type={'password'}
@ -73,7 +74,7 @@ export default () => {
description={'Your new password should be at least 8 characters in length and unique to this website.'} description={'Your new password should be at least 8 characters in length and unique to this website.'}
/> />
</div> </div>
<div className={'mt-6'}> <div css={tw`mt-6`}>
<Field <Field
id={'confirm_password'} id={'confirm_password'}
type={'password'} type={'password'}
@ -81,10 +82,10 @@ export default () => {
label={'Confirm New Password'} label={'Confirm New Password'}
/> />
</div> </div>
<div className={'mt-6'}> <div css={tw`mt-6`}>
<button className={'btn btn-primary btn-sm'} disabled={isSubmitting || !isValid}> <Button size={'small'} disabled={isSubmitting || !isValid}>
Update Password Update Password
</button> </Button>
</div> </div>
</Form> </Form>
</React.Fragment> </React.Fragment>

View file

@ -1,20 +1,97 @@
import React from 'react'; import React from 'react';
import classNames from 'classnames'; import styled, { css } from 'styled-components/macro';
import tw from 'twin.macro';
type Props = { isLoading?: boolean } & React.DetailedHTMLProps<React.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>; interface Props {
isLoading?: boolean;
size?: 'xsmall' | 'small' | 'large' | 'xlarge';
color?: 'green' | 'red' | 'primary' | 'grey';
isSecondary?: boolean;
disabled?: boolean;
}
export default ({ isLoading, children, className, ...props }: Props) => ( const StyledButton = styled.button<Props>`
<button ${tw`rounded p-2 uppercase tracking-wide text-sm transition-all duration-150`};
{...props}
className={classNames('btn btn-sm relative', className)} ${props => props.isSecondary && css<Props>`
> ${tw`border border-neutral-600 bg-transparent text-neutral-200`};
&:hover:not(:disabled) {
${tw`border-neutral-500 text-neutral-100`};
${props => props.color === 'red' && tw`bg-red-500 border-red-600 text-red-50`};
${props => props.color === 'green' && tw`bg-green-500 border-green-600 text-green-50`};
}
`};
${props => (!props.color || props.color === 'primary') && css<Props>`
${props => !props.isSecondary && tw`bg-primary-500 border-primary-600 border text-primary-50`};
&:hover:not(:disabled) {
${tw`bg-primary-600 border-primary-700`};
}
`};
${props => props.color === 'grey' && css`
${tw`border border-neutral-600 bg-neutral-500 text-neutral-50`};
&:hover:not(:disabled) {
${tw`bg-neutral-600 border-neutral-700`};
}
`};
${props => props.color === 'green' && css<Props>`
${tw`border border-green-600 bg-green-500 text-green-50`};
&:hover:not(:disabled) {
${tw`bg-green-600 border-green-700`};
}
${props => props.isSecondary && css`
&:active:not(:disabled) {
${tw`bg-green-600 border-green-700`};
}
`};
`};
${props => props.color === 'red' && css<Props>`
${tw`border border-red-600 bg-red-500 text-red-50`};
&:hover:not(:disabled) {
${tw`bg-red-600 border-red-700`};
}
${props => props.isSecondary && css`
&:active:not(:disabled) {
${tw`bg-red-600 border-red-700`};
}
`};
`};
${props => props.size === 'xsmall' && tw`p-2 text-xs`};
${props => (!props.size || props.size === 'small') && tw`p-3`};
${props => props.size === 'large' && tw`p-4 text-sm`};
${props => props.size === 'xlarge' && tw`p-4 w-full`};
&:disabled { opacity: 0.55; cursor: default }
${props => props.disabled && css`opacity: 0.55; cursor: default`};
`;
type ComponentProps = Props &
Omit<React.DetailedHTMLProps<React.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, keyof Props>;
const Button: React.FC<ComponentProps> = ({ children, isLoading, ...props }) => (
<StyledButton {...props}>
{isLoading && {isLoading &&
<div className={'w-full flex absolute justify-center'} style={{ marginLeft: '-0.75rem' }}> <div css={tw`w-full flex absolute justify-center`} style={{ marginLeft: '-0.75rem' }}>
<div className={'spinner-circle spinner-white spinner-sm'}/> <div className={'spinner-circle spinner-white spinner-sm'}/>
</div> </div>
} }
<span className={isLoading ? 'text-transparent' : undefined}> <span css={isLoading && tw`text-transparent`}>
{children} {children}
</span> </span>
</button> </StyledButton>
); );
export default Button;

View file

@ -1,7 +1,7 @@
import * as React from 'react'; import React from 'react';
import classNames from 'classnames';
import FlashMessageRender from '@/components/FlashMessageRender'; import FlashMessageRender from '@/components/FlashMessageRender';
import SpinnerOverlay from '@/components/elements/SpinnerOverlay'; import SpinnerOverlay from '@/components/elements/SpinnerOverlay';
import tw from 'twin.macro';
type Props = Readonly<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement> & { type Props = Readonly<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement> & {
title?: string; title?: string;
@ -12,16 +12,19 @@ type Props = Readonly<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElemen
const ContentBox = ({ title, borderColor, showFlashes, showLoadingOverlay, children, ...props }: Props) => ( const ContentBox = ({ title, borderColor, showFlashes, showLoadingOverlay, children, ...props }: Props) => (
<div {...props}> <div {...props}>
{title && <h2 className={'text-neutral-300 mb-4 px-4'}>{title}</h2>} {title && <h2 css={tw`text-neutral-300 mb-4 px-4 text-2xl`}>{title}</h2>}
{showFlashes && {showFlashes &&
<FlashMessageRender <FlashMessageRender
byKey={typeof showFlashes === 'string' ? showFlashes : undefined} byKey={typeof showFlashes === 'string' ? showFlashes : undefined}
className={'mb-4'} css={tw`mb-4`}
/> />
} }
<div className={classNames('bg-neutral-700 p-4 rounded shadow-lg relative', borderColor, { <div
'border-t-4': !!borderColor, css={[
})}> tw`bg-neutral-700 p-4 rounded shadow-lg relative`,
!!borderColor && tw`border-t-4`,
]}
>
<SpinnerOverlay visible={showLoadingOverlay || false}/> <SpinnerOverlay visible={showLoadingOverlay || false}/>
{children} {children}
</div> </div>

View file

@ -6,17 +6,45 @@ import DashboardContainer from '@/components/dashboard/DashboardContainer';
import TransitionRouter from '@/TransitionRouter'; import TransitionRouter from '@/TransitionRouter';
import AccountApiContainer from '@/components/dashboard/AccountApiContainer'; import AccountApiContainer from '@/components/dashboard/AccountApiContainer';
import NotFound from '@/components/screens/NotFound'; import NotFound from '@/components/screens/NotFound';
import styled from 'styled-components/macro';
import tw from 'twin.macro';
import config from '@/../../tailwind.config.js';
const SubNavigation = styled.div`
${tw`w-full bg-neutral-700 shadow`};
& > div {
${tw`flex items-center text-sm mx-auto px-2`};
max-width: 1200px;
& > a, & > div {
${tw`inline-block py-3 px-4 text-neutral-300 no-underline transition-all duration-150`};
&:not(:first-of-type) {
${tw`ml-2`};
}
&:active, &:hover {
${tw`text-neutral-100`};
}
&:active, &:hover, &.active {
box-shadow: inset 0 -2px ${config.theme.colors.cyan['500']};
}
}
}
`;
export default ({ location }: RouteComponentProps) => ( export default ({ location }: RouteComponentProps) => (
<> <>
<NavigationBar/> <NavigationBar/>
{location.pathname.startsWith('/account') && {location.pathname.startsWith('/account') &&
<div id={'sub-navigation'}> <SubNavigation>
<div className={'items'}> <div>
<NavLink to={'/account'} exact>Settings</NavLink> <NavLink to={'/account'} exact>Settings</NavLink>
<NavLink to={'/account/api'}>API Credentials</NavLink> <NavLink to={'/account/api'}>API Credentials</NavLink>
</div> </div>
</div> </SubNavigation>
} }
<TransitionRouter> <TransitionRouter>
<Switch location={location}> <Switch location={location}>