Skip to content

Commit

Permalink
Implement code review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
estyxx committed Aug 17, 2024
1 parent 29940c6 commit af9b496
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const MyGrantProfilePageHandler = () => {
},
});

const grant = me?.grant;
const grant = me.grant;

return (
<Page endSeparator={false}>
Expand Down
46 changes: 22 additions & 24 deletions frontend/src/components/my-grant-profile-page-handler/my-grant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { useCurrentLanguage } from "~/locale/context";
import { DeadlineStatus, Status as GrantStatus } from "~/types";
import type { MyProfileWithGrantQuery } from "~/types";

import { getCountryLabel } from "~/helpers/country-utils";
import { useCountries } from "~/helpers/use-countries";
import { createHref } from "../link";
import { Sidebar } from "./sidebar";
Expand All @@ -22,21 +23,18 @@ type Props = {
deadline: MyProfileWithGrantQuery["conference"]["deadline"];
};

const grantManageableStatuses = [
GrantStatus.WaitingForConfirmation,
GrantStatus.Confirmed,
GrantStatus.WaitingList,
GrantStatus.WaitingListMaybe,
];

export const MyGrant = ({ grant, deadline }: Props) => {
const language = useCurrentLanguage();
const countries = useCountries();

const canManageGrant = [
GrantStatus.WaitingForConfirmation,
GrantStatus.Confirmed,
GrantStatus.WaitingList,
GrantStatus.WaitingListMaybe,
].includes(grant.status);

const getCountryLabel = (value: string): string | undefined => {
const country = countries.find((country) => country.value === value);
return country ? country.label : undefined;
};
const canManageGrant = grantManageableStatuses.includes(grant.status);

const dateFormatter = new Intl.DateTimeFormat(language, {
day: "numeric",
Expand Down Expand Up @@ -94,23 +92,23 @@ export const MyGrant = ({ grant, deadline }: Props) => {
)}

<Grid cols={3} gap="small" fullWidth>
<GridColumn>
<div>
<Title>
<FormattedMessage id="grants.form.fields.name" />
</Title>
<Spacer size="xs" />
<Text>{grant.name}</Text>
</GridColumn>
</div>

<GridColumn>
<div>
<Title>
<FormattedMessage id="grants.form.fields.fullName" />
</Title>
<Spacer size="xs" />
<Text>{grant.fullName}</Text>
</GridColumn>
</div>

<GridColumn>
<div>
<Title>
<FormattedMessage id="grants.form.fields.ageGroup" />
</Title>
Expand All @@ -121,27 +119,27 @@ export const MyGrant = ({ grant, deadline }: Props) => {
id={`grants.form.fields.ageGroup.values.${grant.ageGroup}`}
/>
</Text>
</GridColumn>
</div>

<GridColumn>
<div>
<Title>
<FormattedMessage id="grants.form.fields.travellingFrom" />
</Title>
<Spacer size="xs" />
<Text>{getCountryLabel(grant.travellingFrom)}</Text>
</GridColumn>
<Text>{getCountryLabel(countries, grant.travellingFrom)}</Text>
</div>

<GridColumn>
<div>
<Title>
<FormattedMessage id="grants.form.fields.gender" />
</Title>
<Spacer size="xs" />
<Text>
<FormattedMessage id={`profile.gender.${grant.gender}`} />
</Text>
</GridColumn>
</div>

<GridColumn>
<div>
<Title>
<FormattedMessage id="grants.form.fields.occupation" />
</Title>
Expand All @@ -151,7 +149,7 @@ export const MyGrant = ({ grant, deadline }: Props) => {
id={`grants.form.fields.occupation.values.${grant.occupation}`}
/>
</Text>
</GridColumn>
</div>
</Grid>
</VerticalStack>
</GridColumn>
Expand Down
58 changes: 34 additions & 24 deletions frontend/src/components/my-grant-profile-page-handler/no-grant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { FormattedMessage } from "react-intl";
import { useCurrentLanguage } from "~/locale/context";
import { DeadlineStatus, type MyProfileWithSubmissionsQuery } from "~/types";

import { Link } from "@python-italia/pycon-styleguide";
import { createHref } from "../link";

type Props = {
Expand All @@ -26,9 +27,26 @@ export const NoGrant = ({ deadline }: Props) => {
<FormattedMessage id="profile.myGrant.noGrant.heading" />
</Heading>
<Spacer size="small" />
<Text size={2}>
<Text>
{deadlineStatus === DeadlineStatus.HappeningNow && (
<FormattedMessage id="profile.myGrant.noGrant.body.canSubmit" />
<FormattedMessage
id="profile.myGrant.noGrant.body.canSubmit"
values={{
grantInfoLink: (
<Link
href={createHref({
path: "/grants-info",
locale: language,
})}
target="_blank"
>
<Text decoration="underline">
<FormattedMessage id="global.here" />
</Text>
</Link>
),
}}
/>
)}
{deadlineStatus === DeadlineStatus.InThePast && (
<FormattedMessage id="profile.myGrant.noGrant.body.closed" />
Expand All @@ -37,28 +55,20 @@ export const NoGrant = ({ deadline }: Props) => {
<FormattedMessage id="profile.myGrant.noGrant.body.openingSoon" />
)}
</Text>
<Spacer size="large" />
{deadlineStatus === DeadlineStatus.HappeningNow && (
<Button
href={createHref({
path: "/grants",
locale: language,
})}
variant="secondary"
>
<FormattedMessage id="profile.myGrant.noGrant.submitGrant" />
</Button>
)}
{deadlineStatus === DeadlineStatus.InTheFuture && (
<Button
href={createHref({
path: "/grants-info",
locale: language,
})}
variant="secondary"
>
<FormattedMessage id="profile.myGrant.noGrant.submitGrant" />
</Button>
{(deadlineStatus === DeadlineStatus.HappeningNow ||
deadlineStatus === DeadlineStatus.InTheFuture) && (
<>
<Spacer size="large" />
<Button
href={createHref({
path: "/grants-info",
locale: language,
})}
variant="secondary"
>
<FormattedMessage id="profile.myGrant.noGrant.submitGrant" />
</Button>
</>
)}
</Container>
);
Expand Down
56 changes: 27 additions & 29 deletions frontend/src/components/my-grant-profile-page-handler/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,39 +29,37 @@ export const Sidebar = ({
needAccommodation,
}: Props) => {
return (
<>
<MultiplePartsCard>
<GrantInfo label={<FormattedMessage id="profile.myGrant.status" />}>
<Tag color={getStatusColor(status)}>
<FormattedMessage id={`profile.myGrant.status.${status}`} />
</Tag>
</GrantInfo>
<MultiplePartsCard>
<GrantInfo label={<FormattedMessage id="profile.myGrant.status" />}>
<Tag color={getStatusColor(status)}>
<FormattedMessage id={`profile.myGrant.status.${status}`} />
</Tag>
</GrantInfo>

<GrantInfo label={<FormattedMessage id="profile.myGrant.grantType" />}>
<FormattedMessage
id={`grants.form.fields.grantType.values.${grantType}`}
/>
</GrantInfo>
<GrantInfo label={<FormattedMessage id="profile.myGrant.grantType" />}>
<FormattedMessage
id={`grants.form.fields.grantType.values.${grantType}`}
/>
</GrantInfo>

<GrantInfo label={<FormattedMessage id="profile.myGrant.appliedFor" />}>
<VerticalStack gap="small">
<FormattedMessage id="profile.myGrant.appliedFor.ticket" />
<GrantInfo label={<FormattedMessage id="profile.myGrant.appliedFor" />}>
<VerticalStack gap="small">
<FormattedMessage id="profile.myGrant.appliedFor.ticket" />

{needsFundsForTravel && (
<Text size="label2" weight="strong">
<FormattedMessage id="profile.myGrant.appliedFor.travel" />
</Text>
)}
{needsFundsForTravel && (
<Text size="label2" weight="strong">
<FormattedMessage id="profile.myGrant.appliedFor.travel" />
</Text>
)}

{needAccommodation && (
<Text size="label2" weight="strong">
<FormattedMessage id="profile.myGrant.appliedFor.accommodation" />
</Text>
)}
</VerticalStack>
</GrantInfo>
</MultiplePartsCard>
</>
{needAccommodation && (
<Text size="label2" weight="strong">
<FormattedMessage id="profile.myGrant.appliedFor.accommodation" />
</Text>
)}
</VerticalStack>
</GrantInfo>
</MultiplePartsCard>
);
};

Expand Down
7 changes: 7 additions & 0 deletions frontend/src/helpers/country-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const getCountryLabel = (
countries: { label: string; value: string; disabled: boolean }[],
value: string,
): string | undefined => {
const country = countries.find((country) => country.value === value);
return country ? country.label : undefined;
};
14 changes: 7 additions & 7 deletions frontend/src/locale/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ Use the 'Manage' button on the page to confirm or decline the grant. You have un
"profile.myGrant.manage": "Manage",
"profile.myGrant.manage.warning": `If your plans change or you cannot attend the conference anymore, please let us know by clicking the 'Manage' button to refuse your grant or email us at {grantsEmail} as soon as possible.
Failing to notify us may impact your eligibility for financial aid at future events.`,
"profile.myGrant.noGrant.heading": "You haven't requested a grant yet",
"profile.myGrant.noGrant.body.canSubmit":
"If you're facing financial difficulties and wish to attend PyCon Italia, our grant application form is currently open. Submit your grant request today!",
"profile.myGrant.noGrant.heading": "You haven't requested a grant",
"profile.myGrant.noGrant.body.canSubmit": `If you're facing financial difficulties and wish to attend PyCon Italia, our grant application form is currently open!
Find our more information {grantInfoLink} and submit your application below.`,
"profile.myGrant.noGrant.submitGrant": "Request a grant",
"profile.myGrant.noGrant.body.closed":
"The grant application form is currently closed. Stay tuned for future opportunities.",
Expand Down Expand Up @@ -2006,12 +2006,12 @@ Usa il pulsante 'Gestisci' nella pagina per confermare o rifiutare il grant. Hai
"profile.myGrant.status.did_not_attend": "Non ha partecipato",
"profile.myGrant.status.did_not_attend.nextSteps":
"Non hai partecipato alla conferenza.",
"profile.myGrant.noGrant.heading": "Non hai ancora richiesto un grant",
"profile.myGrant.noGrant.body.canSubmit":
"Se ti trovi in difficoltà economica e desideri partecipare a PyCon Italia, il nostro modulo per la richiesta di grant è attualmente aperto. Invia la tua richiesta oggi stesso!",
"profile.myGrant.noGrant.heading": "Non hai richiesto un grant",
"profile.myGrant.noGrant.body.canSubmit": `Se ti trovi in difficoltà economica e desideri partecipare a PyCon Italia, il nostro modulo per la richiesta di grant è attualmente aperto.
Guarda {grantInfoLink} per maggiori informazioni e invia la richiesta qui sotto.`,
"profile.myGrant.noGrant.submitGrant": "Richiedi un grant",
"profile.myGrant.noGrant.body.closed":
"Il modulo per la richiesta di grant è attualmente chiuso. Continua a seguirci per future opportunità.",
"Il modulo per la richiesta di grant è attualmente chiuso. Purtroppo non possiamo accettare nuove richieste dopo la scadenza.",
"profile.myGrant.noGrant.body.openingSoon":
"Il nostro modulo per la richiesta di grant aprirà presto! Visita la nostra pagina informativa per ulteriori dettagli.",

Expand Down

0 comments on commit af9b496

Please sign in to comment.