-
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.
- Loading branch information
1 parent
14b2142
commit 0f766cb
Showing
9 changed files
with
275 additions
and
126 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
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,118 @@ | ||
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' | ||
|
||
export const generateStatusTag = ( | ||
status: GrantStatus, | ||
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 parseStatus = ( | ||
grant: Grant, | ||
formatMessage: FormatMessage, | ||
): { label: string; variant: TagVariant } | undefined => { | ||
switch (status) { | ||
case GrantStatus.Open: | ||
locale: Locale, | ||
): Status => { | ||
switch (grant.status) { | ||
case GrantStatus.Closed: { | ||
return { | ||
applicationStatus: 'closed', | ||
deadlineStatus: grant.dateTo | ||
? formatMessage(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 { | ||
label: formatMessage(m.search.applicationOpen), | ||
variant: 'mint', | ||
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.Closed: | ||
} | ||
case GrantStatus.ClosedWithNote: { | ||
return { | ||
label: formatMessage(m.search.applicationClosed), | ||
variant: 'rose', | ||
applicationStatus: 'closed', | ||
deadlineStatus: formatMessage(m.search.applicationSeeDescription), | ||
note: grant.statusText ?? undefined, | ||
} | ||
case GrantStatus.SeeDescription: | ||
} | ||
case GrantStatus.AlwaysOpen: { | ||
return { | ||
label: formatMessage(m.search.applicationSeeDescription), | ||
variant: 'purple', | ||
applicationStatus: 'open', | ||
deadlineStatus: formatMessage(m.search.applicationAlwaysOpen), | ||
note: grant.statusText ?? undefined, | ||
} | ||
default: | ||
return | ||
} | ||
case GrantStatus.Open: { | ||
return { | ||
applicationStatus: 'open', | ||
deadlineStatus: grant.dateFrom | ||
? formatMessage(m.search.applicationOpensAt, { | ||
arg: formatDate(new Date(grant.dateFrom), locale, 'dd.MMMM.'), | ||
}) | ||
: formatMessage(m.search.applicationOpen), | ||
note: grant.statusText ?? undefined, | ||
} | ||
} | ||
case GrantStatus.OpenWithNote: { | ||
return { | ||
applicationStatus: 'open', | ||
deadlineStatus: formatMessage(m.search.applicationSeeDescription), | ||
note: grant.statusText ?? undefined, | ||
} | ||
} | ||
default: { | ||
return { | ||
applicationStatus: 'unknown', | ||
deadlineStatus: '', | ||
} | ||
} | ||
} | ||
} | ||
|
||
export const generateStatusTag = ( | ||
status: Status['applicationStatus'], | ||
formatMessage: 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
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
Oops, something went wrong.