-
Notifications
You must be signed in to change notification settings - Fork 19
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
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
a1e9fe7
WIP
estyxx cb71b94
Fix ESLint
estyxx be1c7a8
Implement code review suggestions
estyxx 333d1c6
Split component
estyxx c0cd389
Redirect to profile/my-grant when grant exists
estyxx cf62abe
Move queryMyGrant on top
estyxx 651d815
Remove unused vars
estyxx 4efd852
Remove unused vars
estyxx 8c929b5
Chage colors
estyxx 5ff3027
Add GrantInfo component
estyxx 99a73b0
Fix grid
estyxx 4f20823
Apply suggestions from code review
estyxx 6a63356
Apply code review suggestions
estyxx 1eb102f
Revert
estyxx f2aa851
Rephrase
estyxx 02e4318
Fix tests
estyxx 97846fb
Fix tests
estyxx 9b403b1
Fix missing gender
estyxx 4f0cfdc
Rename component
estyxx b865a01
Fix text
estyxx 9f3b860
Handle grant deadline not exists
estyxx 66ccb82
Fix text
estyxx 68255ac
Fix if
estyxx 9260366
Fix text
estyxx babae17
Fix deadline not exists
estyxx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
74 changes: 74 additions & 0 deletions
74
frontend/src/components/my-grant-profile-page-handler/grant-table-info.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,74 @@ | ||
import { Grid, Spacer, Text } from "@python-italia/pycon-styleguide"; | ||
import { FormattedMessage } from "react-intl"; | ||
|
||
import type { MyProfileWithGrantQuery } from "~/types"; | ||
|
||
import { TableItemHeader } from "~/components/table-item-header"; | ||
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" />}> | ||
{grant.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> | ||
<TableItemHeader>{label}</TableItemHeader> | ||
<Spacer size="xs" /> | ||
<Text>{children}</Text> | ||
</div> | ||
); | ||
}; |
40 changes: 40 additions & 0 deletions
40
frontend/src/components/my-grant-profile-page-handler/index.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,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> | ||
); | ||
}; |
135 changes: 135 additions & 0 deletions
135
frontend/src/components/my-grant-profile-page-handler/my-grant.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,135 @@ | ||
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 ( | ||
marcoacierno marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<> | ||
<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> | ||
)} | ||
|
||
{canManageGrant && ( | ||
<Text> | ||
<FormattedMessage id="profile.myGrant.manage.warning" /> | ||
</Text> | ||
)} | ||
</VerticalStack> | ||
</GridColumn> | ||
</Grid> | ||
</> | ||
); | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.