Skip to content

Commit

Permalink
Merge pull request #35 from nathanvale/27-on-xl-desktop-look-at-cente…
Browse files Browse the repository at this point in the history
…ring-the-auth-ui-shell-like-medium-approach

27-on-xl-desktop-look-at-centering-the-auth-ui-shell-like-medium-approach
  • Loading branch information
nathanvale committed Jul 10, 2023
2 parents 1582e4b + 2587cc7 commit bf47bc1
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 177 deletions.
41 changes: 41 additions & 0 deletions app/components/auth-shell.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { ThemeSwitch } from '~/routes/resources+/theme/index.tsx'

export interface AuthShellProps {
children: React.ReactNode
title: string
}

export function AuthShell({ children, title }: AuthShellProps) {
return (
<div className="relative flex h-screen w-screen items-center justify-center">
<div className="flex w-full md:w-auto lg:max-w-7xl">
<div className="container relative flex h-screen flex-col pt-32 sm:grid md:items-center md:justify-center md:px-32 md:pt-0 md:shadow-lg lg:h-[800px] lg:grid-cols-2 lg:px-0">
<ThemeSwitch className="absolute right-4 top-4 md:right-8 md:top-8" />
<div className="relative hidden h-full flex-col bg-muted p-10 text-white dark:border-r lg:flex">
<div className="absolute inset-0 bg-surface-02dp" />
<div className="relative z-20 flex items-center text-lg font-medium">
Bookit
</div>
<div className="relative z-20 mt-auto">
<blockquote className="space-y-2">
<p className="text-lg">
The bookit app is amazing, it has completely changed my
business!
</p>
<footer className="text-sm">Nathan Vale</footer>
</blockquote>
</div>
</div>
<div className="w-full lg:p-8">
<div className="mx-auto flex w-full flex-col justify-center space-y-9 sm:w-[350px]">
<div className="mb-2 flex flex-col space-y-2 text-center md:mb-4">
<h1 className="text-4xl font-black tracking-tight">{title}</h1>
</div>
{children}
</div>
</div>
</div>
</div>
</div>
)
}
46 changes: 8 additions & 38 deletions app/routes/_auth+/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { authenticator, requireAnonymous } from '~/utils/auth.server.ts'
import { commitSession, getSession } from '~/utils/session.server.ts'
import { InlineLogin } from '../resources+/login.tsx'
import { Verifier, unverifiedSessionKey } from '../resources+/verify.tsx'
import { ThemeSwitch } from '../resources+/theme/index.tsx'
import { AuthShell } from '~/components/auth-shell.tsx'

export async function loader({ request }: DataFunctionArgs) {
await requireAnonymous(request)
Expand Down Expand Up @@ -40,43 +40,13 @@ export default function LoginPage() {
const redirectTo = searchParams.get('redirectTo') || '/'

return (
<>
<div className="container relative flex h-[800px] flex-col items-center justify-center sm:grid lg:max-w-none lg:grid-cols-2 lg:px-0">
<ThemeSwitch className="absolute right-4 top-4 md:right-8 md:top-8" />
<div className="relative hidden h-full flex-col bg-muted p-10 text-white dark:border-r lg:flex">
<div className="absolute inset-0 bg-surface-02dp" />
<div className="relative z-20 flex items-center text-lg font-medium">
Bookit
</div>
<div className="relative z-20 mt-auto">
<blockquote className="space-y-2">
<p className="text-lg">
The bookit app is amazing, it has completely changed my
business!
</p>
<footer className="text-sm">Nathan Vale</footer>
</blockquote>
</div>
</div>
<div className="w-full lg:p-8">
<div className="mx-auto flex w-full flex-col justify-center space-y-9 sm:w-[350px]">
<div className="flex flex-col space-y-2 text-center">
<h1 className="text-2xl font-semibold tracking-tight">
Log in to your account
</h1>
<p className="text-sm text-muted-foreground">
Welcome back! We're so excited to see you again!
</p>
</div>
{data.unverified ? (
<Verifier redirectTo={redirectTo} />
) : (
<InlineLogin redirectTo={redirectTo} formError={data.formError} />
)}
</div>
</div>
</div>
</>
<AuthShell title="Welcome back!">
{data.unverified ? (
<Verifier redirectTo={redirectTo} />
) : (
<InlineLogin redirectTo={redirectTo} formError={data.formError} />
)}
</AuthShell>
)
}

Expand Down
142 changes: 4 additions & 138 deletions app/routes/ddb.tsx
Original file line number Diff line number Diff line change
@@ -1,141 +1,7 @@
import React from 'react'
import { parse, useForm } from '@conform-to/react'
import type { ActionArgs } from '@remix-run/node'
import { json } from '@remix-run/node'
import { Form, useActionData } from '@remix-run/react'
import { Input } from '~/components/ui/input.tsx'
import { FormField } from '~/components/form/form-field.tsx'
import { FormItem } from '~/components/form/form-item.tsx'
import { FormLabel } from '~/components/form/form-label.tsx'
import { FormControl } from '~/components/form/form-control.tsx'
import { FormDescription } from '~/components/form/form-description.tsx'
import { FormMessage } from '~/components/form/form-message.tsx'
import { Checkbox } from '~/components/ui/checkbox.tsx'

interface SignupForm {
email: string
password: string
confirmPassword: string
}

function parseFormData(formData: FormData) {
return parse<SignupForm>(formData, {
resolve({ email, password, confirmPassword }) {
const error: Record<string, string> = {}

if (!email) {
error.email = 'Email is required'
} else if (!email.includes('@')) {
error.email = 'Email is invalid'
}

if (!password) {
error.password = 'Password is required'
}

if (!confirmPassword) {
error.confirmPassword = 'Confirm password is required'
} else if (confirmPassword !== password) {
error.confirmPassword = 'Password does not match'
}

if (error.email || error.password || error.confirmPassword) {
return { error }
}

// Return the value only if no error
return {
value: {
email,
password,
confirmPassword,
},
}
},
})
}

export async function action({ request }: ActionArgs) {
const formData = await request.formData()
const submission = parseFormData(formData)

/**
* Signup only when the user click on the submit button and no error found
*/
if (!submission.value || submission.intent !== 'submit') {
// Always sends the submission state back to client until the user is signed up
return json({
...submission,
payload: {
// Never send the password back to client
email: submission.payload.email,
},
})
}

throw new Error('Not implemented')
}

export default function Signup() {
// Last submission returned by the server
const lastSubmission = useActionData<typeof action>()
const [form, { email}] = useForm({
// Sync the result of last submission
lastSubmission,

// Reuse the validation logic on the client
onValidate({ formData }) {
return parseFormData(formData)
},
})

export default function AuthShell() {
return (
<Form method="post" {...form.props}>
<FormField field={email}>
<FormItem>
<FormLabel>Email</FormLabel>
<FormControl>
<Input />
</FormControl>
<FormDescription>This is your public display name</FormDescription>
<FormMessage />
</FormItem>
</FormField>
<div className="items-top flex space-x-2">
<Checkbox id="terms1" />
<div className="grid gap-1.5 leading-none">
<label
htmlFor="terms1"
className="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
>
Accept terms and conditions
</label>
<p className="text-sm text-muted-foreground">
You agree to our Terms of Service and Privacy Policy.
</p>
</div>
</div>

{/* <TextField
label="Email"
message="This is your public display name. It can be your real name or a pseudonym. You can only change this once every 30 days."
placeholder="Password"
config={email}
/>
<TextField
label="Password"
placeholder="Password"
type="password"
config={password}
/>
<TextField
label="Confirm password"
message="Shh!!"
placeholder="Confirm password"
type="password"
config={confirmPassword}
/> */}
<button type="submit">Signup</button>
</Form>
<div className="flex">
<div className="flex h-px max-w-screen-xl bg-surface-03dp">hmm</div>
</div>
)
}
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
"@radix-ui/react-tooltip": "^1.0.6",
"@react-email/components": "^0.0.7",
"@remix-run/css-bundle": "^1.18.0",
"@radix-ui/react-toast": "^1.1.4",
"@remix-run/express": "^1.18.0",
"@remix-run/node": "^1.18.0",
"@remix-run/react": "^1.18.0",
Expand Down
12 changes: 12 additions & 0 deletions tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@ import tailwindcssRadix from 'tailwindcss-radix'
import tailwindcssAnimate from 'tailwindcss-animate'
import defaultTheme from 'tailwindcss/defaultTheme.js'

const boxShadow = {
sm: '0 1px 2px 0 rgb(0 0 0 / 0.05)',
DEFAULT: '0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1)',
md: '0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1)',
lg: '0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1)',
xl: '0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1)',
'2xl': '0 25px 50px -12px rgb(0 0 0 / 0.25)',
inner: 'inset 0 2px 4px 0 rgb(0 0 0 / 0.05)',
none: '0 0 rgb(0, 0 / 0, 0)',
}

export default {
content: ['./app/**/*.{ts,tsx,jsx,js}'],
darkMode: 'class',
Expand All @@ -15,6 +26,7 @@ export default {
},
},
extend: {
shadow: boxShadow,
colors: {
// Generated with other/create-surfaces.ts
surface: {
Expand Down

0 comments on commit bf47bc1

Please sign in to comment.