import { Avatar, Badge, Text, Tooltip, Popover, PopoverTrigger, PopoverContent, PopoverArrow, PopoverBody, } from "@chakra-ui/react"; import { Monospace, RowAction, RowActionsMenu } from "components"; import { intl } from "locale"; import getNiceDNSProvider from "modules/Acmesh"; const errorColor = "red.400"; function ActionsFormatter(rowActions: RowAction[]) { const formatCell = (instance: any) => { return ; }; return formatCell; } function BooleanFormatter() { const formatCell = ({ value }: any) => { return ( {value ? "true" : "false"} ); }; return formatCell; } function CapabilitiesFormatter() { const formatCell = ({ row, value }: any) => { const style = {} as any; if (row?.original?.isDisabled) { style.textDecoration = "line-through"; } if (row?.original?.isSystem) { return ( {intl.formatMessage({ id: "capability.system" })} ); } if (value?.indexOf("full-admin") !== -1) { return ( {intl.formatMessage({ id: "capability.full-admin" })} ); } if (value?.length) { const strs: string[] = []; value.map((c: string) => { strs.push(intl.formatMessage({ id: `capability.${c}` })); return null; }); return ( {intl.formatMessage( { id: "capability-count" }, { count: value.length }, )} ); } return null; }; return formatCell; } function CertificateStatusFormatter() { const formatCell = ({ value, row }: any) => { let color = "cyan.500"; switch (value) { case "failed": color = errorColor; break; case "provided": color = "green.400"; break; case "requesting": color = "yellow.400"; break; } // special case for failed to show an error popover if (value === "failed" && row?.original?.errorMessage) { return ( {intl.formatMessage({ id: value })}
								{row?.original?.errorMessage}
							
); } return {intl.formatMessage({ id: value })}; }; return formatCell; } function CertificateTypeFormatter() { const formatCell = ({ value }: any) => { let color = "cyan.500"; if (value === "dns") { color = "green.400"; } return {intl.formatMessage({ id: value })}; }; return formatCell; } function DisabledFormatter() { const formatCell = ({ value, row }: any) => { if (row?.original?.isDisabled) { return ( {value} ); } return value; }; return formatCell; } function DNSProviderFormatter() { const formatCell = ({ value }: any) => { return getNiceDNSProvider(value); }; return formatCell; } function DomainsFormatter() { const formatCell = ({ value }: any) => { if (value?.length > 0) { return ( <> {value.map((dom: string, idx: number) => { return ( {dom} ); })} ); } return No domains!; }; return formatCell; } function GravatarFormatter() { const formatCell = ({ value }: any) => { return ; }; return formatCell; } function HostStatusFormatter() { const formatCell = ({ row }: any) => { if (row.original.isDisabled) { return ( {intl.formatMessage({ id: "disabled" })} ); } if (row.original.certificateId) { if (row.original.certificate.status === "provided") { return ( {row.original.sslForced ? intl.formatMessage({ id: "https-only" }) : intl.formatMessage({ id: "http-https" })} ); } if (row.original.certificate.status === "error") { return ( {intl.formatMessage({ id: "error" })} ); } return ( {intl.formatMessage({ id: `certificate.${row.original.certificate.status}`, })} ); } return ( {intl.formatMessage({ id: "http-only" })} ); }; return formatCell; } function MonospaceFormatter() { const formatCell = ({ value }: any) => { return {value}; }; return formatCell; } function UpstreamStatusFormatter() { const formatCell = ({ value, row }: any) => { if (value === "ready") { return ( {intl.formatMessage({ id: "ready" })} ); } if (value === "ok") { return ( {intl.formatMessage({ id: "ok" })} ); } if (value === "error") { return ( {intl.formatMessage({ id: "error" })}
								{row?.original?.errorMessage}
							
); } }; return formatCell; } function HostTypeFormatter() { const formatCell = ({ value }: any) => { return intl.formatMessage({ id: `host-type.${value}` }); }; return formatCell; } function IDFormatter() { const formatCell = ({ value }: any) => { return {value}; }; return formatCell; } function SecondsFormatter() { const formatCell = ({ value }: any) => { return intl.formatMessage({ id: "seconds" }, { seconds: value }); }; return formatCell; } export { ActionsFormatter, BooleanFormatter, CapabilitiesFormatter, CertificateStatusFormatter, CertificateTypeFormatter, DisabledFormatter, DNSProviderFormatter, DomainsFormatter, GravatarFormatter, HostStatusFormatter, HostTypeFormatter, IDFormatter, MonospaceFormatter, SecondsFormatter, UpstreamStatusFormatter, };