-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: frontend expiring certification warnings and sign-in prevention #205
Merged
+846
−74
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
614450e
feat: frontend expiring certification warnings and sign-in prevention
mathcolo c5793e3
fix: handle when TZ=Etc/UTC on CI
mathcolo bd1ac00
Bring up to date
mathcolo f54a721
fix: @skyqrose feedback
mathcolo 1df832b
Merge branch 'main' of github.com:mbta/orbit into pim-load-certificat…
mathcolo 5a8f3b8
fix: @skyqrose feedback
mathcolo 53d4ba4
fix: filter by railLine = 'blue'
mathcolo ad122a8
Merge branch 'main' of github.com:mbta/orbit into pim-load-certificat…
mathcolo b2cdad1
Revert "fix: filter by railLine = 'blue'"
mathcolo 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
import { daysBetween } from "../../dateTime"; | ||
import { | ||
Certification, | ||
humanReadableType, | ||
isExpired, | ||
} from "../../models/certification"; | ||
import { className } from "../../util/dom"; | ||
import { DateTime } from "luxon"; | ||
import { ReactElement } from "react"; | ||
|
||
const WARN_WITHIN_D = 60; | ||
|
||
const englishDaysBetween = (now: DateTime, date: DateTime) => { | ||
const delta = daysBetween(now, date); | ||
const wholeAbs = Math.abs(Math.ceil(delta)); | ||
if (delta <= -2) { | ||
return `expired ${wholeAbs} days ago`; | ||
} else if (delta <= -1) { | ||
return "expired yesterday"; | ||
} else if (delta <= 0) { | ||
return "expired today"; | ||
} else if (delta <= 1) { | ||
return "expires tomorrow"; | ||
} else { | ||
return `expires in ${wholeAbs} days`; | ||
} | ||
}; | ||
|
||
const CertificateBox = ({ | ||
now, | ||
mode, | ||
title, | ||
operatorName, | ||
certifications, | ||
}: { | ||
now: DateTime; | ||
mode: "warning" | "error"; | ||
title: string; | ||
operatorName: string; | ||
certifications: Certification[]; | ||
}): ReactElement => { | ||
const innerString = | ||
`Our records show that ${operatorName}'s ` + | ||
certifications | ||
.map( | ||
(c) => | ||
`${humanReadableType(c.type)} ${englishDaysBetween( | ||
now, | ||
c.expires, | ||
)} on ${c.expires.toLocaleString(DateTime.DATE_SHORT)}`, | ||
) | ||
.join(" and ") + | ||
"."; | ||
return ( | ||
<div | ||
className={className([ | ||
"mb-4 mt-2 flex flex-row rounded border-0 px-3 py-2", | ||
mode === "warning" && "bg-[#FFDE9E]", | ||
mode === "error" && "bg-[#FF919A]", | ||
])} | ||
> | ||
<div className="m-0 flex-1 text-xs leading-4"> | ||
<p className="font-bold uppercase">{title}</p> | ||
<p className="mt-2">{innerString}</p> | ||
{mode === "warning" && ( | ||
<p className="mt-2">Please have them call the Office.</p> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export const CertificateBoxes = ({ | ||
now, | ||
displayName, | ||
ignoreExpired, | ||
certifications, | ||
}: { | ||
now: DateTime; | ||
displayName: string; | ||
ignoreExpired: boolean; | ||
certifications: Certification[]; | ||
}): ReactElement => { | ||
const expired = certifications.filter((cert) => isExpired(cert, now)); | ||
const expiresSoon = certifications.filter((cert) => { | ||
const delta = daysBetween(now, cert.expires); | ||
return !isExpired(cert, now) && delta <= WARN_WITHIN_D; | ||
}); | ||
return ( | ||
<> | ||
{expiresSoon.length > 0 && ( | ||
<CertificateBox | ||
now={now} | ||
mode="warning" | ||
title={ | ||
expiresSoon.length === 1 ? "Card expires soon" : "Cards expire soon" | ||
} | ||
operatorName={displayName} | ||
certifications={expiresSoon} | ||
/> | ||
)} | ||
{expired.length > 0 && !ignoreExpired && ( | ||
<CertificateBox | ||
now={now} | ||
mode="error" | ||
title={expired.length === 1 ? "Expired card" : "Expired cards"} | ||
operatorName={displayName} | ||
certifications={expired} | ||
/> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export const Bypass = ({ | ||
displayName, | ||
expireds, | ||
onContinue, | ||
}: { | ||
displayName: string; | ||
expireds: Certification[]; | ||
onContinue: () => void; | ||
}): ReactElement => { | ||
return ( | ||
<> | ||
<hr className="h-[2px] bg-gray-300" /> | ||
<div className="m-2 text-sm text-gray-400"> | ||
<p>Is this warning incorrect?</p> | ||
<span> | ||
If {displayName} has a valid{" "} | ||
{expireds.map((c) => humanReadableType(c.type)).join(" and ")}: | ||
</span> | ||
<ol className="mb-4 ml-10 mr-0 mt-2 list-decimal"> | ||
<li className="m-0"> | ||
Take a picture of {expireds.length === 1 ? "the card" : "the cards"} | ||
. | ||
</li> | ||
<li className="m-0">Email pictures to supervisors.</li> | ||
<li className="m-0">Continue to Fit for Duty Check.</li> | ||
</ol> | ||
<button className="underline" onClick={onContinue}> | ||
Continue to Fit for Duty Check → | ||
</button> | ||
</div> | ||
</> | ||
); | ||
}; |
Oops, something went wrong.
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.
A previous version (when there was the WarningParagraph component) had some extra classes.
light:bg-opacity-40 dark:bg-opacity-30 dark:text-white
. Did you mean to remove those in f54a721 ? (Also, I don't thinkborder-0
is needed anymore, since no border should be the default.)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.
Indeed, all intentional 👍 we don't have light/dark mode and the colors are exact. thanks for catching border-0!