feat(calendar): add calendar to home page
This commit is contained in:
parent
758afb36b9
commit
a3e7224087
6 changed files with 39 additions and 24 deletions
|
@ -1,22 +1,17 @@
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { RedirectButton } from '@/components/buttons/redirect-button';
|
import Calendar from '@/components/calendar';
|
||||||
import { useGetApiUserMe } from '@/generated/api/user/user';
|
import { useGetApiUserMe } from '@/generated/api/user/user';
|
||||||
|
|
||||||
export default function Home() {
|
export default function Home() {
|
||||||
const { data, isLoading } = useGetApiUserMe();
|
const { data } = useGetApiUserMe();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='flex flex-col items-center justify-center h-full'>
|
<div className='max-h-full'>
|
||||||
<div>
|
<Calendar
|
||||||
<h1>
|
userId={data?.data.user?.id}
|
||||||
Hello{' '}
|
height='calc(100svh - 50px - (var(--spacing) * 2 * 5))'
|
||||||
{isLoading ? 'Loading...' : data?.data.user?.name || 'Unknown User'}
|
/>
|
||||||
</h1>
|
|
||||||
<RedirectButton redirectUrl='/logout' buttonText='Logout' />
|
|
||||||
<RedirectButton redirectUrl='/settings' buttonText='Settings' />
|
|
||||||
<RedirectButton redirectUrl='/events/new' buttonText='New Event' />
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
|
|
@ -217,6 +217,10 @@ export const GET = auth(async function GET(req, { params }) {
|
||||||
|
|
||||||
return returnZodTypeCheckedResponse(UserCalendarResponseSchema, {
|
return returnZodTypeCheckedResponse(UserCalendarResponseSchema, {
|
||||||
success: true,
|
success: true,
|
||||||
calendar,
|
calendar: calendar.filter(
|
||||||
|
(event, index, self) =>
|
||||||
|
self.findIndex((e) => e.id === event.id && e.type === event.type) ===
|
||||||
|
index,
|
||||||
|
),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -41,7 +41,13 @@ const DaDRBCalendar = withDragAndDrop<
|
||||||
|
|
||||||
const localizer = momentLocalizer(moment);
|
const localizer = momentLocalizer(moment);
|
||||||
|
|
||||||
export default function Calendar({ userId }: { userId?: string }) {
|
export default function Calendar({
|
||||||
|
userId,
|
||||||
|
height,
|
||||||
|
}: {
|
||||||
|
userId?: string;
|
||||||
|
height: string;
|
||||||
|
}) {
|
||||||
return (
|
return (
|
||||||
<QueryErrorResetBoundary>
|
<QueryErrorResetBoundary>
|
||||||
{({ reset }) => (
|
{({ reset }) => (
|
||||||
|
@ -62,9 +68,9 @@ export default function Calendar({ userId }: { userId?: string }) {
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{userId ? (
|
{userId ? (
|
||||||
<CalendarWithUserEvents userId={userId} />
|
<CalendarWithUserEvents userId={userId} height={height} />
|
||||||
) : (
|
) : (
|
||||||
<CalendarWithoutUserEvents />
|
<CalendarWithoutUserEvents height={height} />
|
||||||
)}
|
)}
|
||||||
</ErrorBoundary>
|
</ErrorBoundary>
|
||||||
)}
|
)}
|
||||||
|
@ -72,7 +78,13 @@ export default function Calendar({ userId }: { userId?: string }) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function CalendarWithUserEvents({ userId }: { userId: string }) {
|
function CalendarWithUserEvents({
|
||||||
|
userId,
|
||||||
|
height,
|
||||||
|
}: {
|
||||||
|
userId: string;
|
||||||
|
height: string;
|
||||||
|
}) {
|
||||||
const sesstion = useSession();
|
const sesstion = useSession();
|
||||||
const [currentView, setCurrentView] = React.useState<
|
const [currentView, setCurrentView] = React.useState<
|
||||||
'month' | 'week' | 'day' | 'agenda' | 'work_week'
|
'month' | 'week' | 'day' | 'agenda' | 'work_week'
|
||||||
|
@ -131,6 +143,9 @@ function CalendarWithUserEvents({ userId }: { userId: string }) {
|
||||||
components={{
|
components={{
|
||||||
toolbar: CustomToolbar,
|
toolbar: CustomToolbar,
|
||||||
}}
|
}}
|
||||||
|
style={{
|
||||||
|
height: height,
|
||||||
|
}}
|
||||||
onView={setCurrentView}
|
onView={setCurrentView}
|
||||||
view={currentView}
|
view={currentView}
|
||||||
date={currentDate}
|
date={currentDate}
|
||||||
|
@ -213,7 +228,7 @@ function CalendarWithUserEvents({ userId }: { userId: string }) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function CalendarWithoutUserEvents() {
|
function CalendarWithoutUserEvents({ height }: { height: string }) {
|
||||||
const [currentView, setCurrentView] = React.useState<
|
const [currentView, setCurrentView] = React.useState<
|
||||||
'month' | 'week' | 'day' | 'agenda' | 'work_week'
|
'month' | 'week' | 'day' | 'agenda' | 'work_week'
|
||||||
>('week');
|
>('week');
|
||||||
|
@ -224,6 +239,9 @@ function CalendarWithoutUserEvents() {
|
||||||
localizer={localizer}
|
localizer={localizer}
|
||||||
culture='de-DE'
|
culture='de-DE'
|
||||||
defaultView='week'
|
defaultView='week'
|
||||||
|
style={{
|
||||||
|
height: height,
|
||||||
|
}}
|
||||||
components={{
|
components={{
|
||||||
toolbar: CustomToolbar,
|
toolbar: CustomToolbar,
|
||||||
}}
|
}}
|
||||||
|
|
|
@ -3,7 +3,8 @@
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: 12px;
|
gap: 12px;
|
||||||
padding: 16px;
|
padding: calc(var(--spacing) * 2);
|
||||||
|
padding-left: calc(50px + var(--spacing));
|
||||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ export default function Header({
|
||||||
<UserDropdown />
|
<UserDropdown />
|
||||||
</span>
|
</span>
|
||||||
</header>
|
</header>
|
||||||
<main>{children}</main>
|
<main className='max-h-full overflow-y-auto p-5'>{children}</main>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -810,9 +810,6 @@ button.rbc-input::-moz-focus-inner {
|
||||||
-ms-flex-direction: row;
|
-ms-flex-direction: row;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
}
|
}
|
||||||
.rbc-time-header.rbc-overflowing {
|
|
||||||
border-right: 1px solid #ddd;
|
|
||||||
}
|
|
||||||
.rbc-rtl .rbc-time-header.rbc-overflowing {
|
.rbc-rtl .rbc-time-header.rbc-overflowing {
|
||||||
border-right-width: 0;
|
border-right-width: 0;
|
||||||
border-left: 1px solid #ddd;
|
border-left: 1px solid #ddd;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue