Skip to content

Commit

Permalink
created add list and add task functions
Browse files Browse the repository at this point in the history
  • Loading branch information
JVGS1111 committed Jul 29, 2024
1 parent b9231d8 commit 2569250
Show file tree
Hide file tree
Showing 11 changed files with 342 additions and 33 deletions.
77 changes: 76 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,19 @@
"test": "jest --watch"
},
"dependencies": {
"@hookform/resolvers": "^3.9.0",
"@phosphor-icons/react": "^2.1.7",
"@radix-ui/react-radio-group": "^1.2.0",
"@radix-ui/react-select": "^2.1.1",
"classnames": "^2.5.1",
"next": "14.2.5",
"react": "^18",
"react-dom": "^18",
"tailwind-merge": "^2.4.0"
"react-hook-form": "^7.52.1",
"react-toastify": "^10.0.5",
"tailwind-merge": "^2.4.0",
"uuid": "^10.0.0",
"zod": "^3.23.8"
},
"devDependencies": {
"@rocketseat/eslint-config": "^2.2.2",
Expand All @@ -28,6 +33,7 @@
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"@types/uuid": "^10.0.0",
"eslint": "^8",
"eslint-config-next": "14.2.5",
"jest": "^29.7.0",
Expand Down
6 changes: 6 additions & 0 deletions src/components/form/Input/ErrorMessage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
interface ErrorMessageProps {
error: string
}
export function ErrorMessage({ error }: ErrorMessageProps) {
return <div className="text-sm text-red">{error}</div>
}
7 changes: 7 additions & 0 deletions src/models/List.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Task } from './Task'

export interface List {
id: string
title: string
tasks: Task[]
}
8 changes: 8 additions & 0 deletions src/models/Task.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,11 @@ export const taskBgColorArray = [
'bg-card08',
'bg-card09',
]

export interface Task {
id?: string
title: string
completed: boolean
arquived: boolean
icon: string
}
1 change: 1 addition & 0 deletions src/pages/_app.page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import '@/styles/globals.css'
import type { AppProps } from 'next/app'
import 'react-toastify/dist/ReactToastify.css'

export default function App({ Component, pageProps }: AppProps) {
return <Component {...pageProps} />
Expand Down
2 changes: 2 additions & 0 deletions src/pages/_document.page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Html, Head, Main, NextScript } from 'next/document'
import { ToastContainer } from 'react-toastify'

export default function Document() {
return (
Expand All @@ -17,6 +18,7 @@ export default function Document() {
</Head>
<body>
<main className="min-h-screen bg-app-bg">
<ToastContainer />
<Main />
<NextScript />
</main>
Expand Down
31 changes: 29 additions & 2 deletions src/pages/add-list/index.page.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,39 @@
import { ErrorMessage } from '@/components/form/Input/ErrorMessage'
import { InputText } from '@/components/form/Input/TextInput'
import { Header } from '@/components/Header'
import { createList } from '@/services/storage'
import { zodResolver } from '@hookform/resolvers/zod'
import { useRouter } from 'next/router'
import { useForm } from 'react-hook-form'
import { z } from 'zod'

const addListFormSchema = z.object({
listName: z.string().min(3, { message: 'The name of the list is too short' }),
})

type AddListForm = z.infer<typeof addListFormSchema>

export default function AddList() {
const router = useRouter()

const {
register,
handleSubmit,
formState: { errors },
} = useForm<AddListForm>({
resolver: zodResolver(addListFormSchema),
})

function handleCreateList(data: AddListForm) {
createList(data.listName)
}

function goBack() {
router.push('/')
}

return (
<form>
<form onSubmit={handleSubmit(handleCreateList)}>
<Header
title="Create a list for better organization"
variante="create"
Expand All @@ -18,7 +42,10 @@ export default function AddList() {
<div className="mx-auto max-w-app p-6">
<label className="flex flex-col gap-2.5 text-xl font-medium text-title">
What’s the name of the list?
<InputText placeholder="Groceries" />
<InputText placeholder="Groceries" {...register('listName')} />
{errors.listName?.message && (
<ErrorMessage error={errors.listName.message} />
)}
</label>
</div>
</form>
Expand Down
Loading

0 comments on commit 2569250

Please sign in to comment.