Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vcci-news-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
Văn Hoàng
vcci-news-frontend
Commits
1a4b0cb4
Commit
1a4b0cb4
authored
Oct 02, 2026
by
Phạm Quang Bảo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: event
parent
f25d62b4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
55 additions
and
19 deletions
+55
-19
use-event-calendar-posts.ts
...mponents/base/events-calendar/use-event-calendar-posts.ts
+55
-19
No files found.
src/components/base/events-calendar/use-event-calendar-posts.ts
View file @
1a4b0cb4
...
@@ -12,7 +12,7 @@ import {
...
@@ -12,7 +12,7 @@ import {
resolveAssetUrl
,
resolveAssetUrl
,
}
from
"@/lib/utils/post"
;
}
from
"@/lib/utils/post"
;
import
{
MOCK_HOME_POSTS
}
from
"@/mockdata/home-posts"
;
import
{
MOCK_HOME_POSTS
}
from
"@/mockdata/home-posts"
;
import
{
useMemo
}
from
"react"
;
import
{
use
Callback
,
use
Memo
}
from
"react"
;
type
RawHomePost
=
RawEventCalendarPost
;
type
RawHomePost
=
RawEventCalendarPost
;
...
@@ -120,21 +120,10 @@ async function fetchEventCalendarRows(params: GetApiV10PostParams) {
...
@@ -120,21 +120,10 @@ async function fetchEventCalendarRows(params: GetApiV10PostParams) {
return
rows
.
map
<
EventCalendarItem
>
(
mapRawPostToEventCalendarItem
);
return
rows
.
map
<
EventCalendarItem
>
(
mapRawPostToEventCalendarItem
);
}
}
/**
function
createEventCalendarParams
():
GetApiV10PostParams
{
* Params lịch sự kiện theo tháng: filter theo tháng được thực hiện hoàn toàn
* ở BE. Toán tử `[]` = date between; đặt `registration_deadline` cuối cùng
* (trước `[]`) để BE nhận diện đây là monthly-event query (pageSize=0 => trả
* toàn bộ, không giới hạn). Cú pháp `field1|field2|field3[](start|end)` tạo
* điều kiện OR: event rơi vào tháng khi registration_deadline / started_at /
* ended_at nằm trong khoảng tháng đó.
*/
function
createEventCalendarParams
(
currentMonth
:
Date
):
GetApiV10PostParams
{
const
monthStart
=
dayjs
(
currentMonth
).
startOf
(
"month"
).
format
(
"YYYY-MM-DD"
);
const
monthEnd
=
dayjs
(
currentMonth
).
endOf
(
"month"
).
format
(
"YYYY-MM-DDTHH:mm:ss"
);
return
{
return
{
page
:
1
,
page
:
1
,
pageSize
:
0
,
pageSize
:
10
0
,
sortField
:
"started_at"
,
sortField
:
"started_at"
,
sortOrder
:
"asc"
,
sortOrder
:
"asc"
,
priorityFeatured
:
false
,
priorityFeatured
:
false
,
...
@@ -142,15 +131,62 @@ function createEventCalendarParams(currentMonth: Date): GetApiV10PostParams {
...
@@ -142,15 +131,62 @@ function createEventCalendarParams(currentMonth: Date): GetApiV10PostParams {
`category.id==(
${
EVENT_CATEGORY_IDS
.
suKien
}
|
${
EVENT_CATEGORY_IDS
.
daoTao
}
)`
,
`category.id==(
${
EVENT_CATEGORY_IDS
.
suKien
}
|
${
EVENT_CATEGORY_IDS
.
daoTao
}
)`
,
"is_hidden==false"
,
"is_hidden==false"
,
"is_active==true"
,
"is_active==true"
,
"type==event"
,
"type==news"
,
`registration_deadline|started_at|ended_at[](
${
monthStart
}
|
${
monthEnd
}
)`
,
].
join
(
","
),
].
join
(
","
),
};
};
}
}
function
filterEventsByMonth
(
items
:
EventCalendarItem
[],
currentMonth
:
Date
,
):
EventCalendarItem
[]
{
const
monthStart
=
dayjs
(
currentMonth
).
startOf
(
"month"
);
const
monthEnd
=
dayjs
(
currentMonth
).
endOf
(
"month"
);
const
hasDateInMonth
=
(
date
:
dayjs
.
Dayjs
|
null
):
boolean
=>
date
!==
null
&&
!
date
.
isBefore
(
monthStart
,
"day"
)
&&
!
date
.
isAfter
(
monthEnd
,
"day"
);
return
items
.
filter
((
item
)
=>
{
const
startedAt
=
item
.
startedAt
?
dayjs
(
item
.
startedAt
)
:
null
;
const
endedAt
=
item
.
endedAt
?
dayjs
(
item
.
endedAt
)
:
null
;
const
registrationDeadline
=
item
.
registrationDeadline
?
dayjs
(
item
.
registrationDeadline
)
:
null
;
const
eventDates
=
(
item
.
eventDates
??
[])
.
map
((
d
)
=>
dayjs
(
d
))
.
filter
((
d
)
=>
d
.
isValid
());
if
(
!
startedAt
&&
!
endedAt
&&
!
registrationDeadline
&&
eventDates
.
length
===
0
)
{
return
false
;
}
if
(
eventDates
.
length
>
0
)
{
return
eventDates
.
some
((
d
)
=>
hasDateInMonth
(
d
));
}
const
eventStartDate
=
startedAt
||
registrationDeadline
;
const
eventEndDate
=
endedAt
||
registrationDeadline
||
startedAt
;
if
(
eventStartDate
&&
eventEndDate
)
{
return
(
!
eventStartDate
.
isAfter
(
monthEnd
,
"day"
)
&&
!
eventEndDate
.
isBefore
(
monthStart
,
"day"
)
);
}
if
(
startedAt
&&
hasDateInMonth
(
startedAt
))
return
true
;
if
(
endedAt
&&
hasDateInMonth
(
endedAt
))
return
true
;
if
(
registrationDeadline
&&
hasDateInMonth
(
registrationDeadline
))
return
true
;
return
false
;
});
}
export
function
useEventCalendarPosts
(
currentMonth
:
Date
)
{
export
function
useEventCalendarPosts
(
currentMonth
:
Date
)
{
const
params
=
useMemo
(
const
params
=
useMemo
(()
=>
createEventCalendarParams
(),
[]);
()
=>
createEventCalendarParams
(
currentMonth
),
const
selectByMonth
=
useCallback
(
(
items
:
EventCalendarItem
[])
=>
filterEventsByMonth
(
items
,
currentMonth
),
[
currentMonth
],
[
currentMonth
],
);
);
...
@@ -160,11 +196,11 @@ export function useEventCalendarPosts(currentMonth: Date) {
...
@@ -160,11 +196,11 @@ export function useEventCalendarPosts(currentMonth: Date) {
try
{
try
{
return
await
fetchEventCalendarRows
(
params
);
return
await
fetchEventCalendarRows
(
params
);
}
catch
(
error
)
{
}
catch
(
error
)
{
// eslint-disable-next-line no-console
console
.
warn
(
"[useEventCalendarPosts] CMS unavailable, falling back to mock data"
,
error
);
console
.
warn
(
"[useEventCalendarPosts] CMS unavailable, falling back to mock data"
,
error
);
return
MOCK_HOME_POSTS
.
filter
((
item
)
=>
Boolean
(
item
.
registrationDeadline
));
return
MOCK_HOME_POSTS
.
filter
((
item
)
=>
Boolean
(
item
.
registrationDeadline
));
}
}
},
},
select
:
selectByMonth
,
staleTime
:
5
*
60
*
1000
,
staleTime
:
5
*
60
*
1000
,
});
});
...
...
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