Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
sevenpro-frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
FAP
sevenpro-frontend
Commits
472aa36e
Commit
472aa36e
authored
Feb 11, 2025
by
Wellton Quirino
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add middleware routes control, add adjustment in modules course
parent
d389de98
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
83 additions
and
34 deletions
+83
-34
page.tsx
src/app/admin/curso/page.tsx
+63
-33
page.tsx
src/app/contato/page.tsx
+2
-0
search-filter.tsx
src/components/search-filter.tsx
+2
-0
axios.ts
src/lib/axios.ts
+0
-1
middleware.ts
src/middleware.ts
+16
-0
No files found.
src/app/admin/curso/page.tsx
View file @
472aa36e
...
...
@@ -30,42 +30,45 @@ import { zodResolver } from '@hookform/resolvers/zod'
import
{
Box
,
Chip
,
MenuItem
,
TextField
}
from
'@mui/material'
import
{
useMutation
,
useQuery
,
useQueryClient
}
from
'@tanstack/react-query'
import
{
format
}
from
'date-fns'
import
{
CalendarIcon
,
PlusIcon
,
Trash2
}
from
'lucide-react'
import
{
CalendarIcon
,
Trash2
}
from
'lucide-react'
import
{
useState
}
from
'react'
import
{
Controller
,
useForm
}
from
'react-hook-form'
import
{
toast
}
from
'sonner'
import
{
z
}
from
'zod'
// type CoursesProps = {
// name: string
// description: string
// desktopBanner: string
// mobileBanner: string
// duration: number
// startDate: Date
// endDate: Date
// professors: string[]
// workload: number
// areaId: string
// audienceId: string
// categoryId: string
// moduleIds: string[]
// }
// const MAX_FILE_SIZE = 5000000
// const ACCEPTED_IMAGE_TYPES = [
// 'image/jpeg',
// 'image/jpg',
// 'image/png',
// 'image/webp',
// ]
const
FormSchema
=
z
.
object
({
name
:
z
.
string
().
trim
().
min
(
3
,
{
message
:
'Título obrigatório'
}),
description
:
z
.
string
().
trim
().
min
(
3
,
{
message
:
'Descrição obrigatória'
}),
desktopBanner
:
z
.
string
(),
mobileBanner
:
z
.
string
(),
duration
:
z
.
number
(),
desktopBanner
:
z
.
any
(),
// .refine((file) => file?.size <= MAX_FILE_SIZE, `Max image size is 5MB.`)
// .refine(
// (file) => ACCEPTED_IMAGE_TYPES.includes(file?.type),
// 'Only .jpg, .jpeg, .png and .webp formats are supported.',
// ),
mobileBanner
:
z
.
any
(),
// .refine((file) => file?.size <= MAX_FILE_SIZE, `Max image size is 5MB.`)
// .refine(
// (file) => ACCEPTED_IMAGE_TYPES.includes(file?.type),
// 'Only .jpg, .jpeg, .png and .webp formats are supported.',
// ),
startDate
:
z
.
date
().
optional
(),
endDate
:
z
.
date
().
optional
(),
professors
:
z
.
array
(
z
.
string
()),
workload
:
z
.
number
(),
areaId
:
z
.
string
(),
workload
:
z
.
string
(),
areaId
:
z
.
string
()
.
trim
().
min
(
1
,
{
message
:
'Selecione a área'
})
,
audienceId
:
z
.
string
(),
categoryId
:
z
.
string
(),
moduleIds
:
z
.
array
(
z
.
string
()),
moduleIds
:
z
.
array
(
z
.
string
().
trim
().
min
(
1
,
{
message
:
'Selecione um módulo'
}),
),
})
export
default
function
Curso
()
{
...
...
@@ -78,7 +81,7 @@ export default function Curso() {
const
queryClient
=
useQueryClient
()
// const { form.register, watch, handleSubmit, control } = useForm<CoursesProps>()
const
{
register
,
handleSubmit
,
reset
}
=
useForm
<
ModulesProps
>
()
const
{
register
,
handleSubmit
}
=
useForm
<
ModulesProps
>
()
const
form
=
useForm
<
z
.
infer
<
typeof
FormSchema
>>
({
resolver
:
zodResolver
(
FormSchema
),
defaultValues
:
{
...
...
@@ -147,8 +150,6 @@ export default function Curso() {
const
responseModuleId
=
response
.
data
.
id
form
.
setValue
(
'moduleIds'
,
[...
selectedIds
,
responseModuleId
])
reset
()
}
const
selectedIds
=
form
.
watch
(
'moduleIds'
)
||
[]
...
...
@@ -204,20 +205,25 @@ export default function Curso() {
variant=
"standard"
type=
"text"
{
...
form
.
register
('
name
')}
sx=
{
StyledInputs
({
color
:
'#26AAA7'
})
}
sx=
{
StyledInputs
(
form
.
formState
.
errors
.
name
?
{
color
:
'#dc2626'
}
:
{
color
:
'#26AAA7'
},
)
}
/>
{
form
.
formState
.
errors
.
name
&&
(
<
p
>
{
form
.
formState
.
errors
.
name
.
message
}
</
p
>
)
}
<
TextField
type=
"text"
variant=
"standard"
label=
"Área"
select
sx=
{
StyledInputs
({
color
:
'#26AAA7'
})
}
defaultValue=
{
''
}
{
...
form
.
register
('
areaId
')}
sx=
{
StyledInputs
(
form
.
formState
.
errors
.
areaId
?
{
color
:
'#dc2626'
}
:
{
color
:
'#26AAA7'
},
)
}
>
<
MenuItem
value=
""
className=
"hidden"
>
Selecione a área
...
...
@@ -235,8 +241,12 @@ export default function Curso() {
type=
"text"
multiline
rows=
{
4
}
sx=
{
StyledInputs
({
color
:
'#26AAA7'
})
}
{
...
form
.
register
('
description
')}
sx=
{
StyledInputs
(
form
.
formState
.
errors
.
description
?
{
color
:
'#dc2626'
}
:
{
color
:
'#26AAA7'
},
)
}
/>
<
Controller
...
...
@@ -283,6 +293,7 @@ export default function Curso() {
values=
{
valueDesktopBanner
}
label=
"Adicionar banner"
{
...
form
.
register
('
desktopBanner
')}
defaultValue=
{
'testedesktopBanner'
}
/>
</
div
>
<
div
className=
"flex flex-col flex-1 mt-6"
>
...
...
@@ -296,10 +307,25 @@ export default function Curso() {
values=
{
valueMobileBanner
}
label=
"Adicionar banner"
{
...
form
.
register
('
mobileBanner
')}
defaultValue=
{
'testemobileBanner'
}
/>
</
div
>
</
div
>
<
Separator
className=
"!mt-10 !mb-4"
/>
<
h6
className=
"text-xl text-purple-100 mb-4"
>
Horas
</
h6
>
<
TextField
label=
"Total de horas do curso"
variant=
"standard"
type=
"number"
{
...
form
.
register
('
workload
')}
sx=
{
StyledInputs
(
form
.
formState
.
errors
.
workload
?
{
color
:
'#dc2626'
}
:
{
color
:
'#26AAA7'
},
)
}
/>
<
Separator
className=
"!mt-10 !mb-4"
/>
<
h6
className=
"text-xl text-purple-100 mb-4"
>
Datas
</
h6
>
<
div
className=
"flex flex-col space-y-6"
>
...
...
@@ -402,11 +428,15 @@ export default function Curso() {
variant=
"standard"
label=
"Selecione os módulos do curso"
select
sx=
{
StyledInputs
({
color
:
'#26AAA7'
})
}
defaultValue=
{
''
}
value=
""
onChange=
{
handleSelect
}
// {...form.register('moduleIds')}
sx=
{
StyledInputs
(
form
.
formState
.
errors
.
moduleIds
?
{
color
:
'#dc2626'
}
:
{
color
:
'#26AAA7'
},
)
}
>
<
MenuItem
value=
""
className=
"hidden"
>
Selecione os módulos
...
...
@@ -457,7 +487,7 @@ export default function Curso() {
className=
"uppercase w-52 flex items-center gap-2 !mt-8"
onClick=
{
handleSubmit
(
addNewModuler
)
}
>
<
PlusIcon
size=
{
20
}
/>
<
span
>
Criar novo Módulo
</
span
>
<
span
>
Criar novo Módulo
</
span
>
</
Button
>
</
div
>
...
...
src/app/contato/page.tsx
View file @
472aa36e
'use client'
import
{
InputMui
}
from
'@/components/mui/inputs'
import
{
Button
}
from
'@/components/ui/button'
import
{
MenuItem
}
from
'@mui/material'
...
...
src/components/search-filter.tsx
View file @
472aa36e
'use client'
import
{
Search
}
from
'lucide-react'
import
{
useForm
}
from
'react-hook-form'
import
{
InputMui
}
from
'./mui/inputs'
...
...
src/lib/axios.ts
View file @
472aa36e
...
...
@@ -3,7 +3,6 @@ import axios from 'axios'
import
{
destroyCookie
,
parseCookies
}
from
'nookies'
const
{
'sevenpro-token'
:
token
}
=
parseCookies
()
console
.
log
(
'🚀 ~ token:'
,
token
)
export
const
api
=
axios
.
create
({
baseURL
:
process
.
env
.
NEXT_PUBLIC_URL_API
,
...
...
src/middleware.ts
0 → 100644
View file @
472aa36e
import
type
{
NextRequest
}
from
'next/server'
import
{
NextResponse
}
from
'next/server'
export
async
function
middleware
(
request
:
NextRequest
)
{
const
token
=
request
.
cookies
.
get
(
'sevenpro-token'
)?.
value
if
(
!
token
)
{
return
NextResponse
.
redirect
(
new
URL
(
'/login'
,
request
.
url
))
}
return
NextResponse
.
next
()
}
export
const
config
=
{
matcher
:
[
'/admin/:path*'
],
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment