-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(web): updated grant status logic (#17127)
* feat: updated status logic * feat: add time values * feat: add time part * chore: remove conidtional * chore: remove imports * fix: wrong message id * fix: add /en locale * fix: undefined if empty array --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
- Loading branch information
1 parent
de0bf4c
commit 992ef02
Showing
13 changed files
with
347 additions
and
130 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import withApollo from '@island.is/web/graphql/withApollo' | ||
import { withLocale } from '@island.is/web/i18n' | ||
import GrantSinglePage from '@island.is/web/screens/Grants/Grant/Grant' | ||
import { getServerSidePropsWrapper } from '@island.is/web/utils/getServerSidePropsWrapper' | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore make web strict | ||
// | ||
const Screen = withApollo(withLocale('en')(GrantSinglePage)) | ||
|
||
export default Screen | ||
|
||
export const getServerSideProps = getServerSidePropsWrapper(Screen) |
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,12 @@ | ||
import withApollo from '@island.is/web/graphql/withApollo' | ||
import { withLocale } from '@island.is/web/i18n' | ||
import GrantsSearchResults from '@island.is/web/screens/Grants/SearchResults/SearchResults' | ||
import { getServerSidePropsWrapper } from '@island.is/web/utils/getServerSidePropsWrapper' | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore make web strict | ||
// | ||
const Screen = withApollo(withLocale('en')(GrantsSearchResults)) | ||
|
||
export default Screen | ||
|
||
export const getServerSideProps = getServerSidePropsWrapper(Screen) |
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,11 @@ | ||
import withApollo from '@island.is/web/graphql/withApollo' | ||
import { withLocale } from '@island.is/web/i18n' | ||
import GrantsHome from '@island.is/web/screens/Grants/Home/GrantsHome' | ||
import { getServerSidePropsWrapper } from '@island.is/web/utils/getServerSidePropsWrapper' | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore make web strict | ||
const Screen = withApollo(withLocale('en')(GrantsHome)) | ||
|
||
export default Screen | ||
|
||
export const getServerSideProps = getServerSidePropsWrapper(Screen) |
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
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
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 |
---|---|---|
@@ -1,29 +1,131 @@ | ||
import { TagVariant } from '@island.is/island-ui/core' | ||
import format from 'date-fns/format' | ||
import localeEn from 'date-fns/locale/en-GB' | ||
import localeIS from 'date-fns/locale/is' | ||
|
||
import { FormatMessage } from '@island.is/localization' | ||
import { GrantStatus } from '@island.is/web/graphql/schema' | ||
import { Locale } from '@island.is/shared/types' | ||
import { Grant, GrantStatus } from '@island.is/web/graphql/schema' | ||
|
||
import { m } from './messages' | ||
import { IntlFormatters, IntlShape } from 'react-intl' | ||
|
||
export const generateStatusTag = ( | ||
status: GrantStatus, | ||
formatMessage: FormatMessage, | ||
): { label: string; variant: TagVariant } | undefined => { | ||
switch (status) { | ||
case GrantStatus.Open: | ||
interface Status { | ||
applicationStatus: 'open' | 'closed' | 'unknown' | ||
deadlineStatus: string | ||
note?: string | ||
} | ||
|
||
const formatDate = ( | ||
date: Date, | ||
locale: Locale, | ||
stringFormat = 'dd.MMMM yyyy', | ||
) => | ||
format(date, stringFormat, { | ||
locale: locale === 'is' ? localeIS : localeEn, | ||
}) | ||
|
||
export const containsTimePart = (date: string) => date.includes('T') | ||
|
||
export const parseStatus = ( | ||
grant: Grant, | ||
formatMessage: IntlShape['formatMessage'], | ||
locale: Locale, | ||
): Status => { | ||
switch (grant.status) { | ||
case GrantStatus.Closed: { | ||
return { | ||
applicationStatus: 'closed', | ||
deadlineStatus: grant.dateTo | ||
? formatMessage( | ||
containsTimePart(grant.dateTo) | ||
? m.search.applicationWasOpenToAndWith | ||
: m.search.applicationWasOpenTo, | ||
{ | ||
arg: formatDate(new Date(grant.dateTo), locale), | ||
}, | ||
) | ||
: formatMessage(m.search.applicationClosed), | ||
note: grant.statusText ?? undefined, | ||
} | ||
} | ||
case GrantStatus.ClosedOpeningSoon: { | ||
return { | ||
applicationStatus: 'closed', | ||
deadlineStatus: grant.dateFrom | ||
? formatMessage(m.search.applicationOpensAt, { | ||
arg: formatDate(new Date(grant.dateFrom), locale), | ||
}) | ||
: formatMessage(m.search.applicationClosed), | ||
note: grant.statusText ?? undefined, | ||
} | ||
} | ||
case GrantStatus.ClosedOpeningSoonWithEstimation: { | ||
return { | ||
applicationStatus: 'closed', | ||
deadlineStatus: grant.dateFrom | ||
? formatMessage(m.search.applicationEstimatedOpensAt, { | ||
arg: formatDate(new Date(grant.dateFrom), locale, 'MMMM yyyy'), | ||
}) | ||
: formatMessage(m.search.applicationClosed), | ||
note: grant.statusText ?? undefined, | ||
} | ||
} | ||
case GrantStatus.ClosedWithNote: { | ||
return { | ||
applicationStatus: 'closed', | ||
deadlineStatus: formatMessage(m.search.applicationSeeDescription), | ||
note: grant.statusText ?? undefined, | ||
} | ||
} | ||
case GrantStatus.AlwaysOpen: { | ||
return { | ||
label: formatMessage(m.search.applicationOpen), | ||
variant: 'mint', | ||
applicationStatus: 'open', | ||
deadlineStatus: formatMessage(m.search.applicationAlwaysOpen), | ||
note: grant.statusText ?? undefined, | ||
} | ||
case GrantStatus.Closed: | ||
} | ||
case GrantStatus.Open: { | ||
return { | ||
label: formatMessage(m.search.applicationClosed), | ||
variant: 'rose', | ||
applicationStatus: 'open', | ||
deadlineStatus: grant.dateTo | ||
? formatMessage( | ||
containsTimePart(grant.dateTo) | ||
? m.search.applicationOpensToWithDay | ||
: m.search.applicationOpensTo, | ||
{ | ||
arg: formatDate(new Date(grant.dateTo), locale, 'dd.MMMM.'), | ||
}, | ||
) | ||
: formatMessage(m.search.applicationOpen), | ||
note: grant.statusText ?? undefined, | ||
} | ||
case GrantStatus.SeeDescription: | ||
} | ||
case GrantStatus.OpenWithNote: { | ||
return { | ||
label: formatMessage(m.search.applicationSeeDescription), | ||
variant: 'purple', | ||
applicationStatus: 'open', | ||
deadlineStatus: formatMessage(m.search.applicationSeeDescription), | ||
note: grant.statusText ?? undefined, | ||
} | ||
default: | ||
return | ||
} | ||
default: { | ||
return { | ||
applicationStatus: 'unknown', | ||
deadlineStatus: '', | ||
} | ||
} | ||
} | ||
} | ||
|
||
export const generateStatusTag = ( | ||
status: Status['applicationStatus'], | ||
formatMessage: IntlShape['formatMessage'], | ||
) => | ||
status !== 'unknown' | ||
? { | ||
label: | ||
status === 'open' | ||
? formatMessage(m.search.applicationOpen) | ||
: formatMessage(m.search.applicationClosed), | ||
variant: status === 'open' ? ('mint' as const) : ('rose' as const), | ||
} | ||
: undefined |
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
Oops, something went wrong.