Skip to content

Commit

Permalink
Refactored issues caught by SQ
Browse files Browse the repository at this point in the history
  • Loading branch information
annstriganova committed Dec 26, 2023
1 parent e7dd093 commit 0c19851
Show file tree
Hide file tree
Showing 31 changed files with 94 additions and 96 deletions.
Empty file added .env
Empty file.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ yarn-error.log*

# typescript
*.tsbuildinfo
next-env.d.ts
next-env.d.ts

.idea
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@
"editor.defaultFormatter": "esbenp.prettier-vscode", // Tell VSCode to use Prettier as default file formatter
"typescript.preferences.quoteStyle": "single",
"javascript.preferences.quoteStyle": "single",
"editor.tabSize": 2
"editor.tabSize": 2,
"[typescriptreact]": {
"editor.defaultFormatter": "vscode.typescript-language-features"
}
}
2 changes: 0 additions & 2 deletions src/app/@parallel/(.)auth/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import AuthModalLogin from '@/app/auth/login/page'

const AuthPage = () => {
return (
<>
<AuthModalLogin />
</>
)
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/_components/CircleAddBtn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import circle_btn from '../../../public/plus.svg'

export default function CircleAddBtn({ onClick }: { onClick: () => void }) {
return (
<div onClick={onClick}>
<div onClick={onClick} onKeyDown={onClick}>
<button
className={
'flex h-12 w-12 cursor-pointer items-center justify-center rounded-full bg-inverted hover:bg-fullpage-tint'
Expand Down
2 changes: 1 addition & 1 deletion src/app/_components/ProductCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function ProductCard({
name,
price,
description,
}: CardProps) {
}: Readonly<CardProps>) {
const addToCart = useCombinedStore((state) => state.add)

return (
Expand Down
2 changes: 0 additions & 2 deletions src/app/auth/registration/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import AuthModalRegistr from '@/components/modals/AuthModalRegistration'

const RegisterParallelRoute = () => {
return (
<>
<AuthModalRegistr />
</>
)
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/cart/_components/CartElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function CartElement({
add,
remove,
removeAll,
}: CartElementProps) {
}: Readonly<CartElementProps>) {
const { name, price, description } = product.info

const addProduct = () => {
Expand Down
3 changes: 0 additions & 3 deletions src/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,7 @@
-ms-border-radius: 50%;
-o-border-radius: 50%;
margin-top: 5px;
color: #2D3748;
display: flex;
width: 32px;
height: 32px;
flex-direction: column;
justify-content: center;
align-items: center;
Expand Down
2 changes: 1 addition & 1 deletion src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface RootLayoutProps {
children: React.ReactNode
}

export default function RootLayout({ children }: RootLayoutProps) {
export default function RootLayout({ children }: Readonly<RootLayoutProps>) {
return (
<html lang="en">
<body className={inter.className + ' flex min-h-screen flex-col'}>
Expand Down
2 changes: 1 addition & 1 deletion src/app/product/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async function getProductById(id: string): Promise<IProduct> {
return result
}

export default async function Page({ params }: ProductProps) {
export default async function Page({ params }: Readonly<ProductProps>) {
const product = await getProductById(params.id)

return (
Expand Down
2 changes: 1 addition & 1 deletion src/app/product/_components/AddToCart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type Props = {
product: IProduct
}

export default function AddToCartButton({ product }: Props) {
export default function AddToCartButton({ product }: Readonly<Props>) {
const [add, remove] = useCombinedStore((state) => [state.add, state.remove])
const items = useStoreData(useCombinedStore, (state) => state.items)
const { name, price, description, active, quantity } = product
Expand Down
6 changes: 3 additions & 3 deletions src/app/product/error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import { useRouter } from 'next/navigation'
import { useEffect } from 'react'

export default function Error({
export default function RenderError({
error,
reset,
}: {
}: Readonly<{
error: Error
reset: () => void
}) {
}>) {
const router = useRouter()

useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/app/product/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ interface ProductLayoutProps {
children: React.ReactNode
}

export default function ProductLayout({ children }: ProductLayoutProps) {
export default function ProductLayout({ children }: Readonly<ProductLayoutProps>) {
return <div>{children}</div>
}
2 changes: 1 addition & 1 deletion src/app/profile/_components/FilledProfile/FiledProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const FiledProfile = () => {
<FormProfile
onSuccessEdit={handleSuccessEdit}
updateUserData={setUserData}
initialUserData={userData || {}}
initialUserData={userData ?? {}}
/>
)}
<div className="mt-[51px]">
Expand Down
30 changes: 14 additions & 16 deletions src/app/profile/_components/FormProfile/FormProfile.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use client'
import 'react-calendar/dist/Calendar.css'
import { editUserProfile } from '@/services/userService'
import { editUserProfile, UserData } from '@/services/userService'
import { useState } from 'react'
import { useAuthStore } from '@/store/authStore'
import { useForm, SubmitHandler } from 'react-hook-form'
import { UserData } from '@/services/userService'
import { FormProfileProps } from './index'
import { isValid as isValidDate, format } from 'date-fns'
import { validationSchema } from '@/validation/userFormSchema'
Expand All @@ -24,8 +23,8 @@ const FormProfile = ({
onSuccessEdit,
updateUserData,
initialUserData,
}: FormProfileProps) => {
const [isCalendarOpen, setCalendarOpen] = useState(false)
}: Readonly<FormProfileProps>) => {
const [isCalendarOpen, setIsCalendarOpen] = useState(false)
const [date, setDate] = useState<Date | null>(new Date())
const [loadingImg, setLoadingImg] = useState(false)

Expand All @@ -40,7 +39,7 @@ const FormProfile = ({
})

useEscapeKey(() => {
setCalendarOpen(false)
setIsCalendarOpen(false)
})

const { token } = useAuthStore()
Expand Down Expand Up @@ -79,13 +78,13 @@ const FormProfile = ({

// function for opening and closing the calendar
const handleCalendarToggle = () => {
setCalendarOpen(!isCalendarOpen)
setIsCalendarOpen(!isCalendarOpen)
}

// function for closing the calendar by clicking anywhere in the viewport
const clickBackdrop = (e: React.MouseEvent<HTMLDivElement>) => {
const clickBackdrop = (e: React.MouseEvent<HTMLDivElement> | React.KeyboardEvent) => {
if (e.currentTarget === e.target) {
setCalendarOpen(false)
setIsCalendarOpen(false)
}
}

Expand Down Expand Up @@ -150,15 +149,15 @@ const FormProfile = ({
alt="calendar open icon"
width={18}
height={18}
className={`absolute right-10 top-[60%] cursor-pointer transition-transform ${
isCalendarOpen ? 'rotate-180' : ''
}`}
className={`absolute right-10 top-[60%] cursor-pointer transition-transform ${isCalendarOpen ? 'rotate-180' : ''
}`}
onClick={handleCalendarToggle}
/>
{isCalendarOpen && (
<div
className="fixed bottom-0 left-0 right-0 top-0 z-10"
onClick={clickBackdrop}
onKeyDown={clickBackdrop}
>
<div className="z-20">
{isCalendarOpen && (
Expand Down Expand Up @@ -265,11 +264,10 @@ const FormProfile = ({
<div className="mt-4">
<Button
type="submit"
className={`${
Object.keys(errors).length > 0
? 'cursor-not-allowed bg-brand-solid opacity-20'
: 'bg-brand-solid hover:bg-indigo-700'
} mt-[24px] rounded-[47px] border border-transparent px-4 py-2 text-sm font-medium text-white focus:outline-none focus:outline-focus focus:ring-2 focus:ring-offset-2`}
className={`${Object.keys(errors).length > 0
? 'cursor-not-allowed bg-brand-solid opacity-20'
: 'bg-brand-solid hover:bg-indigo-700'
} mt-[24px] rounded-[47px] border border-transparent px-4 py-2 text-sm font-medium text-white focus:outline-none focus:outline-focus focus:ring-2 focus:ring-offset-2`}
>
<span>Save Changes</span>
</Button>
Expand Down
2 changes: 0 additions & 2 deletions src/app/profile/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import FiledProfile from './_components/FilledProfile/FiledProfile'

const ProfilePage = () => {
return (
<>
<FiledProfile />
</>
)
}

Expand Down
4 changes: 3 additions & 1 deletion src/components/CartButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import Link from 'next/link'
export default function CartButton() {
const count = useStoreData(useCombinedStore, (state) => state.count)

const handleClick = () => {}
const handleClick = () => {
// not implemented yet
}

return (
<Link href={'/cart'}>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function Footer() {
</a>
</li>
<li>
Email:
Email:
<span className={'ml-1 underline sm:no-underline'}>
<a
href="mailto:[email protected]"
Expand Down
2 changes: 1 addition & 1 deletion src/components/modals/AuthModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ enum SwitchType {
Registration = 'REGISTRATION',
}

export function AuthModal({ onCloseModal }: LoginModalProps) {
export function AuthModal({ onCloseModal }: Readonly<LoginModalProps>) {
const [switchForm, setSwitchForm] = useState<SwitchType>(SwitchType.Login)
const pathname = usePathname()

Expand Down
2 changes: 1 addition & 1 deletion src/components/modals/AuthModalRegistration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ enum SwitchType {
Registration = 'REGISTRATION',
}

function AuthModalRegistr({ onCloseModal }: AuthModalProps) {
function AuthModalRegistr({ onCloseModal }: Readonly<AuthModalProps>) {
const [switchForm, setSwitchForm] = useState<SwitchType>(
SwitchType.Registration,
)
Expand Down
74 changes: 36 additions & 38 deletions src/components/modals/forms/LoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,43 +59,41 @@ export default function LoginForm() {
}

return (
<>
<form onSubmit={handleSubmit(onSubmit)} className="flex flex-col">
{errors?.root?.serverError.type === '500' && (
<div className="mt-4 text-negative">
{errors?.root?.serverError.message}
</div>
)}
{errors?.root?.serverError.type === '400' && (
<div className="mt-4 text-negative">
{errors?.root?.serverError.message}
</div>
)}
<FormInput
id="email"
register={register}
name="email"
type="text"
label="Enter your email address"
placeholder="Enter your email address"
error={errors.email}
/>
<FormInput
id="password"
register={register}
type="password"
name="password"
label="Password"
placeholder="Password"
error={errors.password}
/>
<Button
type="submit"
className="mt-6 w-full hover:bg-brand-solid-hover"
>
Login
</Button>
</form>
</>
<form onSubmit={handleSubmit(onSubmit)} className="flex flex-col">
{errors?.root?.serverError.type === '500' && (
<div className="mt-4 text-negative">
{errors?.root?.serverError.message}
</div>
)}
{errors?.root?.serverError.type === '400' && (
<div className="mt-4 text-negative">
{errors?.root?.serverError.message}
</div>
)}
<FormInput
id="email"
register={register}
name="email"
type="text"
label="Enter your email address"
placeholder="Enter your email address"
error={errors.email}
/>
<FormInput
id="password"
register={register}
type="password"
name="password"
label="Password"
placeholder="Password"
error={errors.password}
/>
<Button
type="submit"
className="mt-6 w-full hover:bg-brand-solid-hover"
>
Login
</Button>
</form>
)
}
Loading

0 comments on commit 0c19851

Please sign in to comment.