-
Notifications
You must be signed in to change notification settings - Fork 18
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
Add Grant to profile dashboard #3993
base: main
Are you sure you want to change the base?
Changes from all commits
d3b175a
dd84f6f
8bd275e
35017fe
31694bf
28432db
4d6bd6b
338adbb
c83d8e6
10d3af1
9033b50
9c59ad6
02c0d9d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { Grid, Spacer, Text } from "@python-italia/pycon-styleguide"; | ||
import { FormattedMessage } from "react-intl"; | ||
|
||
import type { MyProfileWithGrantQuery } from "~/types"; | ||
|
||
import { Title } from "~/components/title"; | ||
import { getCountryLabel } from "~/helpers/country-utils"; | ||
import { useCountries } from "~/helpers/use-countries"; | ||
|
||
type Props = { | ||
grant: MyProfileWithGrantQuery["me"]["grant"]; | ||
}; | ||
|
||
export const GrantTableInfo = ({ grant }: Props) => { | ||
const countries = useCountries(); | ||
|
||
return ( | ||
<Grid cols={3} gap="small" fullWidth> | ||
<GrantInfo label={<FormattedMessage id="grants.form.fields.name" />}> | ||
{grant.name} | ||
</GrantInfo> | ||
|
||
<GrantInfo label={<FormattedMessage id="grants.form.fields.fullName" />}> | ||
{grant.fullName} | ||
</GrantInfo> | ||
|
||
<GrantInfo label={<FormattedMessage id="grants.form.fields.ageGroup" />}> | ||
{grant.ageGroup && ( | ||
<FormattedMessage | ||
id={`grants.form.fields.ageGroup.values.${grant.ageGroup}`} | ||
/> | ||
)} | ||
</GrantInfo> | ||
|
||
<GrantInfo | ||
label={<FormattedMessage id="grants.form.fields.travellingFrom" />} | ||
> | ||
{getCountryLabel(countries, grant.travellingFrom)} | ||
</GrantInfo> | ||
|
||
<GrantInfo label={<FormattedMessage id="grants.form.fields.gender" />}> | ||
<FormattedMessage id={`profile.gender.${grant.gender}`} /> | ||
</GrantInfo> | ||
|
||
<GrantInfo | ||
label={<FormattedMessage id="grants.form.fields.occupation" />} | ||
> | ||
<FormattedMessage | ||
id={`grants.form.fields.occupation.values.${grant.occupation}`} | ||
/> | ||
</GrantInfo> | ||
</Grid> | ||
); | ||
}; | ||
|
||
const GrantInfo = ({ | ||
label, | ||
children, | ||
}: { | ||
label: React.ReactNode; | ||
children: React.ReactNode; | ||
}) => { | ||
return ( | ||
<div> | ||
<Title>{label}</Title> | ||
<Spacer size="xs" /> | ||
<Text>{children}</Text> | ||
</div> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Heading, Page, Section } from "@python-italia/pycon-styleguide"; | ||
import { FormattedMessage } from "react-intl"; | ||
|
||
import { useMyProfileWithGrantQuery } from "~/types"; | ||
|
||
import { MyGrant } from "~/components/my-grant-profile-page-handler/my-grant"; | ||
import { NoGrant } from "~/components/my-grant-profile-page-handler/no-grant"; | ||
import { MetaTags } from "../meta-tags"; | ||
|
||
export const MyGrantProfilePageHandler = () => { | ||
const { | ||
data: { | ||
me: { grant }, | ||
conference: { deadline }, | ||
}, | ||
} = useMyProfileWithGrantQuery({ | ||
variables: { | ||
conference: process.env.conferenceCode, | ||
}, | ||
}); | ||
|
||
return ( | ||
<Page endSeparator={false}> | ||
<FormattedMessage id="profile.myGrant"> | ||
{(text) => <MetaTags title={text} />} | ||
</FormattedMessage> | ||
|
||
<Section background="green"> | ||
<Heading size="display2"> | ||
<FormattedMessage id="profile.myGrant" /> | ||
</Heading> | ||
</Section> | ||
|
||
<Section> | ||
{grant && <MyGrant grant={grant} deadline={deadline} />} | ||
{!grant && <NoGrant deadline={deadline} />} | ||
</Section> | ||
</Page> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
import { | ||
Button, | ||
Grid, | ||
GridColumn, | ||
Link, | ||
Spacer, | ||
Text, | ||
VerticalStack, | ||
} from "@python-italia/pycon-styleguide"; | ||
import { FormattedMessage } from "react-intl"; | ||
|
||
import { useCurrentLanguage } from "~/locale/context"; | ||
import { DeadlineStatus, Status as GrantStatus } from "~/types"; | ||
import type { MyProfileWithGrantQuery } from "~/types"; | ||
|
||
import { createHref } from "../link"; | ||
import { GrantTableInfo } from "./grant-table-info"; | ||
import { Sidebar } from "./sidebar"; | ||
|
||
type Props = { | ||
grant: MyProfileWithGrantQuery["me"]["grant"]; | ||
deadline: MyProfileWithGrantQuery["conference"]["deadline"]; | ||
}; | ||
|
||
const grantManageableStatuses = [ | ||
GrantStatus.WaitingForConfirmation, | ||
GrantStatus.Confirmed, | ||
GrantStatus.WaitingList, | ||
GrantStatus.WaitingListMaybe, | ||
]; | ||
|
||
export const MyGrant = ({ grant, deadline }: Props) => { | ||
const language = useCurrentLanguage(); | ||
|
||
const canManageGrant = grantManageableStatuses.includes(grant.status); | ||
|
||
const dateFormatter = new Intl.DateTimeFormat(language, { | ||
day: "numeric", | ||
month: "long", | ||
year: "numeric", | ||
}); | ||
|
||
return ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we split this into some sub-components? it is quite a big component There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I moved the table in a separate component. Do you think it's enough? or should I split also the "next steps" section maybe? 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this component is still a bit hard to read but can't think of anything specific now without cloning the code locally and changing it a bit |
||
<> | ||
<Grid cols={12}> | ||
<GridColumn colSpan={4}> | ||
<Sidebar | ||
status={grant.status} | ||
grantType={grant.grantType} | ||
needsFundsForTravel={grant.needsFundsForTravel} | ||
needAccommodation={grant.needAccommodation} | ||
/> | ||
{deadline.status === DeadlineStatus.HappeningNow && ( | ||
<> | ||
<Spacer size="medium" /> | ||
<Button | ||
href={createHref({ | ||
path: "/grants/edit", | ||
locale: language, | ||
})} | ||
size="small" | ||
variant="secondary" | ||
> | ||
<FormattedMessage id="profile.myGrant.edit" /> | ||
</Button> | ||
</> | ||
)} | ||
</GridColumn> | ||
|
||
<GridColumn colSpan={8}> | ||
<VerticalStack gap="medium" justifyContent="spaceBetween" fullHeight> | ||
<div> | ||
<Text size="label3" uppercase weight="strong"> | ||
<FormattedMessage id="profile.myGrant.nextSteps" /> | ||
</Text> | ||
<Spacer size="xs" /> | ||
<Text> | ||
<FormattedMessage | ||
id={`profile.myGrant.status.${grant.status}.nextSteps`} | ||
values={{ | ||
replyDeadline: ( | ||
<Text as="span" weight="strong"> | ||
{dateFormatter.format( | ||
new Date(grant.applicantReplyDeadline), | ||
)} | ||
</Text> | ||
), | ||
}} | ||
/> | ||
</Text> | ||
</div> | ||
|
||
{canManageGrant && ( | ||
<div> | ||
<Button | ||
href={createHref({ | ||
path: "/grants/reply", | ||
locale: language, | ||
})} | ||
size="small" | ||
variant="secondary" | ||
> | ||
<FormattedMessage id="profile.myGrant.manage" /> | ||
</Button> | ||
</div> | ||
)} | ||
|
||
<GrantTableInfo grant={grant} /> | ||
|
||
{deadline.status === DeadlineStatus.HappeningNow && ( | ||
<Text> | ||
<FormattedMessage | ||
id="profile.myGrant.editInfo" | ||
values={{ | ||
editDeadline: ( | ||
<Text as="span" weight="strong"> | ||
{dateFormatter.format(new Date(deadline.end))} | ||
</Text> | ||
), | ||
}} | ||
/> | ||
</Text> | ||
)} | ||
|
||
<Text> | ||
<FormattedMessage | ||
id="profile.myGrant.manage.warning" | ||
values={{ | ||
grantsEmail: ( | ||
<Link target="_blank" href="mailto:grants@pycon.it"> | ||
<Text decoration="underline" weight="strong" color="none"> | ||
grants@pycon.it | ||
</Text> | ||
</Link> | ||
), | ||
}} | ||
/> | ||
</Text> | ||
</VerticalStack> | ||
</GridColumn> | ||
</Grid> | ||
</> | ||
); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the user lands on
pycon.it/grants
page, if they have a grant, it automatically redirects toprofile/my-grant
. This component is only used when the user doesn't have a grant, so I removed the grant's fetching as it's no longer needed.