|
| 1 | +import AlertTitle from "@mui/material/AlertTitle"; |
| 2 | +import type { WorkspaceResource } from "api/typesGenerated"; |
| 3 | +import { Alert, AlertDetail } from "components/Alert/Alert"; |
| 4 | +import { Link } from "components/Link/Link"; |
| 5 | +import { useProxy } from "contexts/ProxyContext"; |
| 6 | +import { useAuthenticated } from "hooks/useAuthenticated"; |
| 7 | +import type { FC } from "react"; |
| 8 | +import { docs } from "utils/docs"; |
| 9 | + |
| 10 | +interface WildcardHostnameWarningProps { |
| 11 | + // If resources are provided, show template-focused warning |
| 12 | + resources?: WorkspaceResource[]; |
| 13 | +} |
| 14 | + |
| 15 | +export const WildcardHostnameWarning: FC<WildcardHostnameWarningProps> = ({ |
| 16 | + resources, |
| 17 | +}) => { |
| 18 | + const { proxy } = useProxy(); |
| 19 | + const { permissions } = useAuthenticated(); |
| 20 | + |
| 21 | + const hasResources = Boolean(resources); |
| 22 | + const canEditDeploymentConfig = Boolean(permissions.editDeploymentConfig); |
| 23 | + |
| 24 | + if (proxy.proxy?.wildcard_hostname) { |
| 25 | + return null; |
| 26 | + } |
| 27 | + |
| 28 | + if (hasResources) { |
| 29 | + const hasSubdomainCoderApp = resources!.some((resource) => { |
| 30 | + return resource.agents?.some((agent) => |
| 31 | + agent.apps?.some((app) => app.subdomain), |
| 32 | + ); |
| 33 | + }); |
| 34 | + |
| 35 | + if (!hasSubdomainCoderApp) { |
| 36 | + return null; |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + return ( |
| 41 | + <Alert |
| 42 | + severity="warning" |
| 43 | + className={ |
| 44 | + hasResources |
| 45 | + ? "rounded-none border-0 border-l-2 border-l-warning border-b-divider" |
| 46 | + : undefined |
| 47 | + } |
| 48 | + > |
| 49 | + <AlertTitle>Some workspace applications will not work</AlertTitle> |
| 50 | + <AlertDetail> |
| 51 | + <div> |
| 52 | + {hasResources |
| 53 | + ? "This template contains coder_app resources with" |
| 54 | + : "One or more apps in this workspace have"}{" "} |
| 55 | + <code className="py-px px-1 bg-surface-tertiary rounded-sm text-content-primary"> |
| 56 | + subdomain = true |
| 57 | + </code> |
| 58 | + {canEditDeploymentConfig ? ( |
| 59 | + <> |
| 60 | + , but subdomain applications are not configured. Users won't be |
| 61 | + able to access these applications until you configure the{" "} |
| 62 | + <code className="py-px px-1 bg-surface-tertiary rounded-sm text-content-primary"> |
| 63 | + --wildcard-access-url |
| 64 | + </code>{" "} |
| 65 | + flag when starting the Coder server. |
| 66 | + </> |
| 67 | + ) : ( |
| 68 | + ", which requires a Coder deployment with a Wildcard Access URL configured. Please contact your administrator." |
| 69 | + )} |
| 70 | + </div> |
| 71 | + <div className="pt-2"> |
| 72 | + <Link |
| 73 | + href={docs("/admin/networking/wildcard-access-url")} |
| 74 | + target="_blank" |
| 75 | + > |
| 76 | + <span className="font-semibold"> |
| 77 | + Learn more about wildcard access URL |
| 78 | + </span> |
| 79 | + </Link> |
| 80 | + </div> |
| 81 | + </AlertDetail> |
| 82 | + </Alert> |
| 83 | + ); |
| 84 | +}; |
0 commit comments