-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
simplify front-end logic. move it to back-end
- Loading branch information
Showing
13 changed files
with
110 additions
and
241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
52 changes: 0 additions & 52 deletions
52
kabinizer-front-end/src/pages/selectPeriods/Calendar/Calendar.tsx
This file was deleted.
Oops, something went wrong.
66 changes: 66 additions & 0 deletions
66
kabinizer-front-end/src/pages/selectPeriods/Calendar/DrawPeriodsCalendar.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { | ||
BookingRequestService, | ||
CreateBookingRequestDto, | ||
DrawService, | ||
} from "../../../../api"; | ||
import { CompareDates } from "@/utils"; | ||
import DrawPeriodMonths from "./Months"; | ||
import { useMutation, useQuery, useQueryClient } from "react-query"; | ||
import useUser from "@/hooks/useUser.tsx"; | ||
import { getMonthsMap, GetWeeklyPeriods } from "@/utils/calendar.ts"; | ||
|
||
const DrawPeriodsCalendar = () => { | ||
const user = useUser(); | ||
const queryClient = useQueryClient(); | ||
|
||
const { data: draws, isLoading: isLoadingDraws } = useQuery( | ||
"getApiDraw", | ||
DrawService.getApiDraw, | ||
); | ||
const { data: bookingRequests, isLoading: isLoadingBookingRequests } = | ||
useQuery( | ||
"myBookingRequests", | ||
() => BookingRequestService.getApiBookingRequestUser(user.localAccountId), | ||
{ enabled: !!user.localAccountId }, | ||
); | ||
|
||
const addBooking = useMutation( | ||
"postApiBooking", | ||
(payload: CreateBookingRequestDto[]) => | ||
BookingRequestService.postApiBookingRequest(payload), | ||
{ onSuccess: () => queryClient.invalidateQueries("myBookingRequests") }, | ||
); | ||
const removeBooking = useMutation( | ||
"deleteApiBooking", | ||
(payload: string[]) => | ||
BookingRequestService.deleteApiBookingRequest(payload), | ||
{ onSuccess: () => queryClient.invalidateQueries("myBookingRequests") }, | ||
); | ||
|
||
if (isLoadingDraws || isLoadingBookingRequests) return <div>Loading...</div>; | ||
|
||
const periods = draws | ||
?.flatMap((value) => value.periods ?? []) | ||
.sort(CompareDates); | ||
|
||
if (!periods?.length) return <div>No periods</div>; | ||
|
||
const monthMap = getMonthsMap(GetWeeklyPeriods(periods, draws || [])); | ||
|
||
const toggleBooking = (periodId: string) => { | ||
const booking = bookingRequests?.find((b) => b.periodId === periodId); | ||
booking?.id | ||
? removeBooking.mutate([booking.id]) | ||
: addBooking.mutate([{ periodId }]); | ||
}; | ||
|
||
return ( | ||
<DrawPeriodMonths | ||
months={monthMap} | ||
selected={bookingRequests || []} | ||
onClick={toggleBooking} | ||
/> | ||
); | ||
}; | ||
|
||
export default DrawPeriodsCalendar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
35 changes: 35 additions & 0 deletions
35
kabinizer-front-end/src/pages/selectPeriods/DrawDeadlines.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { DrawService } from "../../../api"; | ||
import { FormatDate } from "@/utils"; | ||
import { useQuery } from "react-query"; | ||
|
||
const DrawDeadlines = () => { | ||
const { data: draws, isLoading } = useQuery(["getApiDraw"], () => | ||
DrawService.getApiDraw(), | ||
); | ||
if (isLoading) return <div>Loading...</div>; | ||
if (!draws) return <div>No data</div>; | ||
|
||
return ( | ||
<div className="w-full pb-10"> | ||
<div className="rounded-xl bg-[#E6E6E6] p-2"> | ||
<div className="flex justify-end"> | ||
<h2 className="font-poppins font-bold text-[#515151]">Deadline</h2> | ||
</div> | ||
<div className="flex flex-col gap-1"> | ||
{draws?.map((draw) => ( | ||
<div key={draw.id} className="flex justify-between align-middle"> | ||
<p className="text-l font-poppins font-bold text-[#020202]"> | ||
{draw.title} | ||
</p> | ||
<p className="font-poppins text-2xl font-bold text-[#354A71]"> | ||
{draw.end ? FormatDate(new Date(draw.end)) : "–"} | ||
</p> | ||
</div> | ||
))} | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default DrawDeadlines; |
Oops, something went wrong.