| 1 | import { ShieldAlert } from "lucide-react"; |
| 2 | import { Link } from "react-router"; |
| 3 | |
| 4 | import type { PolicyHold } from "@g1t/contracts"; |
| 5 | |
| 6 | /** |
| 7 | * The notice across the top for someone a workspace holds out until they |
| 8 | * meet its policy, such as one that requires two-factor authentication or |
| 9 | * single sign-on: they keep their place and cannot use it until they do. |
| 10 | */ |
| 11 | export function PolicyNotice({ held }: { held: PolicyHold[] }) { |
| 12 | if (held.length === 0) return null; |
| 13 | const twoFactor = held.some((hold) => hold.gap === "two_factor"); |
| 14 | // Single sign-on is one workspace's at a time: the first that asks for it. |
| 15 | const sso = held.find((hold) => hold.gap === "sso"); |
| 16 | return ( |
| 17 | <div |
| 18 | role="alert" |
| 19 | className="flex flex-wrap items-center justify-center gap-x-3 gap-y-1 border-b border-warn/30 bg-warn/10 px-4 py-2 text-center text-sm" |
| 20 | > |
| 21 | <ShieldAlert size={15} aria-hidden="true" className="hidden shrink-0 text-warn sm:block" /> |
| 22 | <span> |
| 23 | {held.map((hold) => hold.reason).join(" ")} |
| 24 | </span> |
| 25 | {twoFactor && ( |
| 26 | <Link to="/settings/two-factor" className="font-medium underline underline-offset-4"> |
| 27 | Turn on two-factor authentication |
| 28 | </Link> |
| 29 | )} |
| 30 | {sso && ( |
| 31 | <Link to={`/auth/sso/${sso.slug}?next=${encodeURIComponent(`/${sso.slug}`)}`} className="font-medium underline underline-offset-4"> |
| 32 | Sign in with {sso.slug}'s single sign-on |
| 33 | </Link> |
| 34 | )} |
| 35 | </div> |
| 36 | ); |
| 37 | } |