Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: show maximum number of ninjas that can enroll on an event #224

Merged
merged 3 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 35 additions & 28 deletions apps/app/components/Event/EventInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,21 @@ import {
CloseCircleOutlined,
EnvironmentOutlined,
HomeOutlined,
TeamOutlined,
} from "@ant-design/icons";

function EventInfo({
start_time,
end_time,
location,
team,
notes,
enrollments_open,
enrollments_close,
event,
enrolledNinjas,
breakpoints = { xs: 1, sm: 1, md: 1, lg: 1, xl: 1, xxl: 6 },
}) {
enrolledNinjas = typeof enrolledNinjas !== "undefined" ? enrolledNinjas : 0;
const labelStyle = { color: "rgba(0, 0, 0, 0.45)", maxWidth: "30vw" };

const timeForEnrollmentsClose = () => {
const enrollmentsClose = new Date(enrollments_close).getTime();
const enrollmentsClose = new Date(event.enrollments_close).getTime();
const nowDate = new Date().getTime();
const timeDiff = (enrollmentsClose - nowDate) / (1000 * 60 * 60 * 24);
const timeDiff = (event.enrollmentsClose - nowDate) / (1000 * 60 * 60 * 24);

return timeDiff > 0 && timeDiff < 1; // Difference of less than a day
};
Expand All @@ -40,7 +37,7 @@ function EventInfo({
}
span={2}
>
{new Date(start_time).toLocaleString("pt", {
{new Date(event.start_time).toLocaleString("pt", {
weekday: "long",
year: "numeric",
month: "long",
Expand All @@ -51,38 +48,45 @@ function EventInfo({
labelStyle={labelStyle}
label={
<span>
<EnvironmentOutlined /> Localização
<AlignLeftOutlined /> Notas
</span>
}
span={5}
>
{location?.name}
{event.notes}
</Descriptions.Item>
<Descriptions.Item
labelStyle={labelStyle}
label={
<span>
<ClockCircleOutlined /> Início
<TeamOutlined /> Limite de Vagas
</span>
}
span={2}
>
{new Date(start_time).toLocaleString("pt", {
hour: "numeric",
minute: "numeric",
})}
{enrolledNinjas} / {event.spots_available}
</Descriptions.Item>

<Descriptions.Item
labelStyle={labelStyle}
label={
<span>
<ClockCircleOutlined /> Fim
<EnvironmentOutlined /> Localização
</span>
}
span={5}
>
{new Date(end_time).toLocaleString("pt", {
{event.location?.name}
</Descriptions.Item>
<Descriptions.Item
labelStyle={labelStyle}
label={
<span>
<ClockCircleOutlined /> Início
</span>
}
span={2}
>
{new Date(event.start_time).toLocaleString("pt", {
hour: "numeric",
minute: "numeric",
})}
Expand All @@ -91,23 +95,26 @@ function EventInfo({
labelStyle={labelStyle}
label={
<span>
<HomeOutlined /> Turma
<ClockCircleOutlined /> Fim
</span>
}
span={2}
span={5}
>
{team?.name}
{new Date(event.end_time).toLocaleString("pt", {
hour: "numeric",
minute: "numeric",
})}
</Descriptions.Item>
<Descriptions.Item
labelStyle={labelStyle}
label={
<span>
<AlignLeftOutlined /> Notas
<HomeOutlined /> Turma
</span>
}
span={5}
span={2}
>
{notes}
{event.team?.name}
</Descriptions.Item>
<Descriptions.Item
labelStyle={labelStyle}
Expand All @@ -118,7 +125,7 @@ function EventInfo({
}
span={2}
>
{new Date(enrollments_open).toLocaleDateString("pt", {
{new Date(event.enrollments_open).toLocaleDateString("pt", {
year: "numeric",
month: "long",
day: "numeric",
Expand All @@ -141,7 +148,7 @@ function EventInfo({
}
span={2}
>
{new Date(enrollments_close).toLocaleDateString("pt", {
{new Date(event.enrollments_close).toLocaleDateString("pt", {
year: "numeric",
month: "long",
day: "numeric",
Expand Down
3 changes: 2 additions & 1 deletion apps/app/components/Event/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const Event = ({
collapsed = true,
details = false,
isLoading = false,
enrolledNinjas,
}) => {
const { user } = useAuth();
const role = user?.role;
Expand Down Expand Up @@ -119,7 +120,7 @@ const Event = ({
</Descriptions.Item>
</Descriptions>
) : (
<EventInfo {...event} />
<EventInfo event={event} enrolledNinjas={enrolledNinjas} />
)}
{role === EUser.Organizer ? (
<>
Expand Down
1 change: 1 addition & 0 deletions apps/app/pages/admin/event/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ function EventPage() {
collapsed={false}
details={true}
isLoading={isLoading}
enrolledNinjas={0}
/>
</Row>
<Divider />
Expand Down
2 changes: 1 addition & 1 deletion apps/app/pages/event/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ function EventPage() {
registerMentorOnEvent(value);
}
};

return (
<AppLayout>
<Title level={2}>Detalhes do evento</Title>
Expand All @@ -223,6 +222,7 @@ function EventPage() {
collapsed={false}
details={true}
isLoading={isLoading}
enrolledNinjas={enrolledNinjas.length}
/>
</Row>
<Col>
Expand Down
2 changes: 1 addition & 1 deletion apps/app/pages/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function Events() {
<Row className={styles.row} align="top" justify="start" gutter={[16, 16]}>
{events?.map((info) => (
<Col key={info.id}>
<Event event={info} loading={isLoading} />
<Event event={info} loading={isLoading} enrolledNinjas={0} />
</Col>
))}
</Row>
Expand Down
7 changes: 6 additions & 1 deletion apps/app/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ function Dashboard() {
event={nextEvent()}
collapsed={false}
isLoading={isLoadingEvents}
enrolledNinjas={0}
/>
) : (
<Typography>Aguarda que o próximo evento seja divulgado</Typography>
Expand All @@ -124,7 +125,11 @@ function Dashboard() {
>
{events?.slice(0, 3).map((event: any) => (
<Col key={event.id}>
<Event event={event} isLoading={isLoadingEvents} />
<Event
event={event}
isLoading={isLoadingEvents}
enrolledNinjas={0}
/>
</Col>
))}
</Row>
Expand Down
Loading