Skip to content

Commit

Permalink
chore: states update, fix styles
Browse files Browse the repository at this point in the history
  • Loading branch information
americano98 committed Nov 29, 2024
1 parent 1ba57d4 commit 01acb4c
Show file tree
Hide file tree
Showing 12 changed files with 130 additions and 75 deletions.
2 changes: 1 addition & 1 deletion packages/ui/src/components/card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as React from 'react'
import { cn } from '@utils/cn'
import { cva, type VariantProps } from 'class-variance-authority'

const cardVariants = cva('bg-card text-card-foreground rounded-lg border shadow', {
const cardVariants = cva('rounded-lg border bg-card text-card-foreground shadow', {
variants: {
variant: {
default: '',
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/src/components/input-otp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const InputOTPSlot = React.forwardRef<HTMLDivElement, InputOTPSlotProps>(({ inde
<div
ref={ref}
className={cn(
'relative flex items-center justify-center h-[52px] w-11 rounded border border-borders-1 p-2 text-xl transition-all',
'relative flex items-center justify-center h-[52px] w-11 rounded border border-borders-1 p-2 text-2xl transition-all',
isActive && 'border-borders-3 z-10',
className
)}
Expand All @@ -49,7 +49,7 @@ const InputOTPSlot = React.forwardRef<HTMLDivElement, InputOTPSlotProps>(({ inde
{char}
{hasFakeCaret && (
<div className="pointer-events-none absolute inset-0 flex items-center justify-center">
<div className="animate-caret-blink bg-foreground h-4 w-px duration-1000" />
<div className="animate-caret-blink h-4 w-px bg-foreground duration-1000" />
</div>
)}
</div>
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/components/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const BaseInput = React.forwardRef<HTMLInputElement, BaseInputProps>(
<input className={cn(commonClassName, specificClassNames, className)} type={type} ref={ref} {...props} />
{error && (
<Text
className="text-foreground-danger absolute top-full leading-none translate-y-1 tracking-tight"
className="absolute top-full translate-y-1 leading-none tracking-tight text-foreground-danger"
weight="light"
size={0}
>
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/components/label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as LabelPrimitive from '@radix-ui/react-label'
import { cn } from '@utils/cn'
import { cva, type VariantProps } from 'class-variance-authority'

const labelVariants = cva('leading-none block peer-disabled:cursor-not-allowed peer-disabled:opacity-70', {
const labelVariants = cva('block leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70', {
variants: {
variant: {
default: 'text-sm leading-none',
Expand Down
6 changes: 3 additions & 3 deletions packages/ui/src/views/auth/components/agreements.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import { Text } from '../../../components'

export function Agreements() {
return (
<Text className="leading-tight mt-auto relative z-10" size={0} color="foreground-5" align="center">
<Text className="relative z-10 mt-auto leading-tight" size={0} color="foreground-5" align="center">
By joining, you agree to{' '}
<Link
className="underline decoration-transparent hover:decoration-foreground-1 transition-colors duration-200 underline-offset-4 decoration-1 text-foreground-1 whitespace-nowrap"
className="whitespace-nowrap text-foreground-1 underline decoration-transparent decoration-1 underline-offset-4 transition-colors duration-200 hover:decoration-foreground-1"
to="/"
>
Terms of Service
</Link>{' '}
and&nbsp;
<Link
className="underline decoration-transparent hover:decoration-foreground-1 transition-colors duration-200 underline-offset-4 decoration-1 text-foreground-1 whitespace-nowrap"
className="whitespace-nowrap text-foreground-1 underline decoration-transparent decoration-1 underline-offset-4 transition-colors duration-200 hover:decoration-foreground-1"
to="/"
>
Privacy Policy
Expand Down
10 changes: 5 additions & 5 deletions packages/ui/src/views/auth/components/animated-harness-logo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ export function AnimatedHarnessLogo({ theme }: AnimatedHarnessLogoProps) {
const isError = theme === 'error'

return (
<div className="relative" aria-hidden>
<div className="relative flex size-16" aria-hidden>
<div className={cn(isError && 'rotate-90', 'transition-transform duration-700')}>
<span
className={cn(
'absolute size-[68px] -left-2.5 -z-10 -top-2 rounded-[100%] transition-colors duration-700 blur-[10px] opacity-[.12]',
shadowBackground
)}
/>
<div className="relative h-16 w-16 bg-background-3 rounded-full overflow-hidden shadow-[0px_0px_20px_0px_rgba(0,0,0,0.6)] flex">
<div className="relative flex size-16 overflow-hidden rounded-full bg-background-3 shadow-[0px_0px_20px_0px_rgba(0,0,0,0.6)]">
<span className="border-linear absolute inset-0 mix-blend-overlay [background:linear-gradient(180deg,#fff,transparent)_border-box]" />
<span className="absolute rounded-full size-7 -right-0.5 blur-[10px] bottom-px bg-[#D9D9D9] opacity-5 translate-y-1/2" />
<span className="absolute -right-0.5 bottom-px size-7 translate-y-1/2 rounded-full bg-[#D9D9D9] opacity-5 blur-[10px]" />
<span
className={cn(
'absolute rounded-full size-7 -right-0.5 blur-[10px] bottom-px transition-colors duration-700 mix-blend-plus-lighter bg-[#7980D2] opacity-10 translate-y-1/2',
Expand All @@ -52,10 +52,10 @@ export function AnimatedHarnessLogo({ theme }: AnimatedHarnessLogoProps) {
largeLightBackground
)}
/>
<span className="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 rotate-45 size-8 rounded-xl bg-gradient-to-r opacity-50 blur-sm from-[#F9F9FA] via-transparent via-60% to-transparent" />
<span className="absolute left-1/2 top-1/2 size-8 -translate-x-1/2 -translate-y-1/2 rotate-45 rounded-xl bg-gradient-to-r from-[#F9F9FA] via-transparent via-60% to-transparent opacity-50 blur-sm" />
</div>
</div>
<Icon className="absolute left-1/2 -translate-x-1/2 -translate-y-1/2 top-1/2 z-10" name="harness" size={36} />
<Icon className="absolute left-1/2 top-1/2 z-10 -translate-x-1/2 -translate-y-1/2" name="harness" size={36} />
</div>
)
}
20 changes: 16 additions & 4 deletions packages/ui/src/views/auth/forgot-password-page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect } from 'react'
import { useEffect, useState } from 'react'
import { SubmitHandler, useForm } from 'react-hook-form'
import { Link } from 'react-router-dom'

Expand All @@ -25,11 +25,13 @@ const forgotPasswordSchema = z.object({
})

export function ForgotPasswordPage({ isLoading, onSubmit, error }: PageProps) {
const [serverError, setServerError] = useState<string | null>(null)
const {
register,
handleSubmit,
setError,
clearErrors,
trigger,
formState: { errors }
} = useForm({
resolver: zodResolver(forgotPasswordSchema)
Expand All @@ -42,19 +44,29 @@ export function ForgotPasswordPage({ isLoading, onSubmit, error }: PageProps) {
}
}

const hasError = Object.keys(errors).length > 0 || !!error
const handleInputChange = async () => {
if (serverError) {
setServerError(null)
clearErrors(['email'])
await trigger()
}
}

useEffect(() => {
if (error) {
setServerError(error)
setError('email', {
type: 'manual',
message: error
})
} else {
setServerError(null)
clearErrors(['email'])
}
}, [error, setError, clearErrors])

const hasError = Object.keys(errors).length > 0 || !!serverError

return (
<Floating1ColumnLayout
className="sm:pt-[186px] pt-20 flex-col bg-background-7"
Expand All @@ -81,8 +93,8 @@ export function ForgotPasswordPage({ isLoading, onSubmit, error }: PageProps) {
id="email"
type="email"
placeholder="Your email"
{...register('email')}
error={errors.email?.message?.toString() || error}
{...register('email', { onChange: handleInputChange })}
error={errors.email?.message?.toString()}
autoFocus
/>
<Button
Expand Down
24 changes: 18 additions & 6 deletions packages/ui/src/views/auth/new-password-page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect } from 'react'
import { useEffect, useState } from 'react'
import { useForm } from 'react-hook-form'

import { zodResolver } from '@hookform/resolvers/zod'
Expand Down Expand Up @@ -31,11 +31,13 @@ const newPasswordSchema = z
})

export function NewPasswordPage({ isLoading, handleFormSubmit, error }: PageProps) {
const [serverError, setServerError] = useState<string | null>(null)
const {
register,
handleSubmit,
setError,
clearErrors,
trigger,
formState: { errors }
} = useForm({
resolver: zodResolver(newPasswordSchema)
Expand All @@ -45,8 +47,17 @@ export function NewPasswordPage({ isLoading, handleFormSubmit, error }: PageProp
handleFormSubmit?.(data)
}

const handleInputChange = async () => {
if (serverError) {
setServerError(null)
clearErrors(['confirmPassword'])
await trigger()
}
}

useEffect(() => {
if (error) {
setServerError(error)
setError('password', {
type: 'manual',
message: ' '
Expand All @@ -56,15 +67,16 @@ export function NewPasswordPage({ isLoading, handleFormSubmit, error }: PageProp
message: error
})
} else {
setServerError(null)
clearErrors(['password', 'confirmPassword'])
}
}, [error, setError, clearErrors])

const hasError = Object.keys(errors).length > 0 || !!error
const hasError = Object.keys(errors).length > 0 || !!serverError

return (
<Floating1ColumnLayout
className="sm:pt-[186px] pt-20 flex-col bg-background-7"
className="flex-col bg-background-7 pt-20 sm:pt-[186px]"
highlightTheme={hasError ? 'error' : 'blue'}
verticalCenter
>
Expand All @@ -87,7 +99,7 @@ export function NewPasswordPage({ isLoading, handleFormSubmit, error }: PageProp
wrapperClassName="mt-2.5"
id="password"
type="password"
{...register('password')}
{...register('password', { onChange: handleInputChange })}
placeholder="Password (6+ characters)"
error={errors.password?.message?.toString()}
/>
Expand All @@ -98,9 +110,9 @@ export function NewPasswordPage({ isLoading, handleFormSubmit, error }: PageProp
wrapperClassName="mt-2.5"
id="confirmPassword"
type="password"
{...register('confirmPassword')}
{...register('confirmPassword', { onChange: handleInputChange })}
placeholder="Confirm password"
error={errors.confirmPassword?.message?.toString() || error}
error={errors.confirmPassword?.message?.toString()}
/>
<Button
className="mt-10 w-full"
Expand Down
31 changes: 14 additions & 17 deletions packages/ui/src/views/auth/otp-page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect } from 'react'
import { useEffect, useState } from 'react'
import { Controller, useForm } from 'react-hook-form'
import { Fragment } from 'react/jsx-runtime'

Expand Down Expand Up @@ -43,15 +43,14 @@ const otpPasswordSchema = z.object({
})

export function OTPPage({ handleResend, isLoading, handleFormSubmit, error }: PageProps) {
const [serverError, setServerError] = useState<string | null>(null)
// TODO: get email from url or from context
const email = '[email protected]'

const {
handleSubmit,
control,
formState: { errors },
setError,
clearErrors,
reset,
watch
} = useForm<OtpPageDataProps>({
Expand All @@ -64,32 +63,29 @@ export function OTPPage({ handleResend, isLoading, handleFormSubmit, error }: Pa
const otpValue = watch('otp')

const onSubmit = (data: OtpPageDataProps) => {
setServerError(null)
handleFormSubmit?.({ ...data, email })
reset()
}

useEffect(() => {
setServerError(null)
if (otpValue.length === OTP_LENGTH) {
handleSubmit(onSubmit)()
}
}, [otpValue, handleSubmit, onSubmit])

const hasError = Object.keys(errors).length > 0 || !!error

useEffect(() => {
if (error) {
setError('otp', {
type: 'manual',
message: error
})
} else {
clearErrors(['otp'])
setServerError(error)
}
}, [error, setError, clearErrors])
}, [error])

const hasError = Object.keys(errors).length > 0 || !!serverError

return (
<Floating1ColumnLayout
className="sm:pt-[186px] pt-20 flex-col bg-background-7"
className="flex-col bg-background-7 pt-20 sm:pt-[186px]"
highlightTheme={hasError ? 'error' : 'blue'}
verticalCenter
>
Expand Down Expand Up @@ -122,15 +118,15 @@ export function OTPPage({ handleResend, isLoading, handleFormSubmit, error }: Pa
</InputOTP>
)}
/>
{(errors.otp || error) && (
{(errors.otp || serverError) && (
<Text
className="text-foreground-danger w-full absolute top-full leading-none translate-y-2 tracking-tight"
className="absolute top-full w-full translate-y-2 leading-none tracking-tight text-foreground-danger"
weight="light"
align="center"
size={1}
as="p"
>
{errors.otp?.message || error}
{errors.otp?.message || serverError}
</Text>
)}
</div>
Expand All @@ -141,14 +137,15 @@ export function OTPPage({ handleResend, isLoading, handleFormSubmit, error }: Pa
type="submit"
size="md"
loading={isLoading}
disabled={hasError}
>
{isLoading ? 'Verifying...' : 'Verify'}
</Button>
</form>
<Spacer size={4} />
<Text className="block" size={2} color="foreground-5" weight="normal" align="center" as="p">
Didn&apos;t receive the code?{' '}
<Button className="p-0 leading-none h-5" variant="link" onClick={handleResend}>
<Button className="h-5 p-0 leading-none" variant="link" onClick={handleResend}>
Resend
</Button>
</Text>
Expand Down
Loading

0 comments on commit 01acb4c

Please sign in to comment.