Nicer cert type create select

This commit is contained in:
Jamie Curnow 2023-02-27 17:21:10 +10:00
parent 6681da605e
commit 83a9666807
No known key found for this signature in database
GPG Key ID: FFBB624C43388E9E
7 changed files with 93 additions and 84 deletions

View File

@ -47,7 +47,6 @@ function LocalePicker({ onChange, className }: LocalPickerProps) {
<MenuItem <MenuItem
icon={<Flag countryCode={getFlagCodeForLocale(item[0])} />} icon={<Flag countryCode={getFlagCodeForLocale(item[0])} />}
onClick={() => changeTo(item[0])} onClick={() => changeTo(item[0])}
// rel={item[1]}
key={`locale-${item[0]}`}> key={`locale-${item[0]}`}>
<span>{intl.formatMessage({ id: `locale-${item[1]}` })}</span> <span>{intl.formatMessage({ id: `locale-${item[1]}` })}</span>
</MenuItem> </MenuItem>

View File

@ -173,7 +173,6 @@ const DesktopNavigation: FC = () => {
navItems.findIndex((item) => { navItems.findIndex((item) => {
// Find the nav item whose location / sub items location is the beginning of the currently active path // Find the nav item whose location / sub items location is the beginning of the currently active path
if (item.to) { if (item.to) {
// console.debug(item.to, path);
if (item.to === "/") { if (item.to === "/") {
return path === item.to; return path === item.to;
} }

View File

@ -0,0 +1,23 @@
import { Button, MenuButton, MenuButtonProps } from "@chakra-ui/react";
import { FiChevronDown } from "react-icons/fi";
function PrettyMenuButton(props: MenuButtonProps) {
return (
<MenuButton
size="sm"
as={Button}
fontFamily="heading"
bgGradient="linear(to-r, red.400,pink.400)"
color="white"
rightIcon={<FiChevronDown />}
_hover={{
bgGradient: "linear(to-r, red.400,pink.400)",
boxShadow: "xl",
}}
{...props}>
{props.children}
</MenuButton>
);
}
export { PrettyMenuButton };

View File

@ -9,6 +9,7 @@ export * from "./Monospace";
export * from "./Navigation"; export * from "./Navigation";
export * from "./Permissions"; export * from "./Permissions";
export * from "./PrettyButton"; export * from "./PrettyButton";
export * from "./PrettyMenuButton";
export * from "./SiteWrapper"; export * from "./SiteWrapper";
export * from "./SpinnerPage"; export * from "./SpinnerPage";
export * from "./Table"; export * from "./Table";

View File

@ -1,8 +1,5 @@
import { useState } from "react";
import { import {
Button, Button,
ButtonGroup,
FormControl, FormControl,
FormErrorMessage, FormErrorMessage,
FormLabel, FormLabel,
@ -24,23 +21,25 @@ import { useSetCertificate } from "hooks";
import { intl } from "locale"; import { intl } from "locale";
import { validateString } from "modules/Validations"; import { validateString } from "modules/Validations";
import CustomForm from "./CustomForm";
import DNSForm from "./DNSForm";
import HTTPForm from "./HTTPForm"; import HTTPForm from "./HTTPForm";
interface CertificateCreateModalProps { interface CertificateCreateModalProps {
isOpen: boolean; isOpen: boolean;
onClose: () => void; onClose: () => void;
certType: string;
} }
function CertificateCreateModal({ function CertificateCreateModal({
isOpen, isOpen,
onClose, onClose,
certType,
}: CertificateCreateModalProps) { }: CertificateCreateModalProps) {
const [certType, setCertType] = useState("");
const toast = useToast(); const toast = useToast();
const { mutate: setCertificate } = useSetCertificate(); const { mutate: setCertificate } = useSetCertificate();
const onModalClose = () => { const onModalClose = () => {
onClose(); onClose();
setCertType("");
}; };
const onSubmit = async ( const onSubmit = async (
@ -98,32 +97,6 @@ function CertificateCreateModal({
</ModalHeader> </ModalHeader>
<ModalCloseButton /> <ModalCloseButton />
<ModalBody> <ModalBody>
{certType === "" ? (
<FormControl>
<FormLabel htmlFor="type">
Select the Certificate Validation method
</FormLabel>
<ButtonGroup style={{ width: "100%" }}>
<Button
onClick={() => setCertType("http")}
style={{ width: "33%" }}>
{intl.formatMessage({ id: "type.http" })}
</Button>
<Button
onClick={() => setCertType("dns")}
style={{ width: "34%" }}>
{intl.formatMessage({ id: "type.dns" })}
</Button>
<Button
onClick={() => setCertType("custom")}
style={{ width: "33%" }}>
{intl.formatMessage({ id: "type.custom" })}
</Button>
</ButtonGroup>
</FormControl>
) : null}
{certType !== "" ? (
<Stack spacing={4}> <Stack spacing={4}>
<Field name="name" validate={validateString(1, 100)}> <Field name="name" validate={validateString(1, 100)}>
{({ field, form }: any) => ( {({ field, form }: any) => (
@ -142,16 +115,15 @@ function CertificateCreateModal({
id: "name", id: "name",
})} })}
/> />
<FormErrorMessage> <FormErrorMessage>{form.errors.name}</FormErrorMessage>
{form.errors.name}
</FormErrorMessage>
</FormControl> </FormControl>
)} )}
</Field> </Field>
</Stack> </Stack>
) : null}
{certType === "http" ? <HTTPForm /> : null} {certType === "http" ? <HTTPForm /> : null}
{certType === "dns" ? <DNSForm /> : null}
{certType === "custom" ? <CustomForm /> : null}
</ModalBody> </ModalBody>
<ModalFooter> <ModalFooter>
{certType !== "" ? ( {certType !== "" ? (

View File

@ -1,12 +1,7 @@
import { useEffect, useReducer, useState } from "react"; import { useEffect, useReducer, useState } from "react";
import { Alert, AlertIcon } from "@chakra-ui/react"; import { Alert, AlertIcon } from "@chakra-ui/react";
import { import { EmptyList, SpinnerPage, tableEventReducer } from "components";
EmptyList,
PrettyButton,
SpinnerPage,
tableEventReducer,
} from "components";
import { useCertificates } from "hooks"; import { useCertificates } from "hooks";
import { intl } from "locale"; import { intl } from "locale";
@ -23,11 +18,7 @@ const initialState = {
], ],
filters: [], filters: [],
}; };
function TableWrapper() {
interface TableWrapperProps {
onCreateClick?: () => void;
}
function TableWrapper({ onCreateClick }: TableWrapperProps) {
const [{ offset, limit, sortBy, filters }, dispatch] = useReducer( const [{ offset, limit, sortBy, filters }, dispatch] = useReducer(
tableEventReducer, tableEventReducer,
initialState, initialState,
@ -68,11 +59,6 @@ function TableWrapper({ onCreateClick }: TableWrapperProps) {
<EmptyList <EmptyList
title={intl.formatMessage({ id: "create-certificate-title" })} title={intl.formatMessage({ id: "create-certificate-title" })}
summary={intl.formatMessage({ id: "create-hint" })} summary={intl.formatMessage({ id: "create-hint" })}
createButton={
<PrettyButton mt={5} onClick={onCreateClick}>
{intl.formatMessage({ id: "lets-go" })}
</PrettyButton>
}
/> />
); );
} }

View File

@ -1,14 +1,22 @@
import { useState } from "react"; import { useState } from "react";
import { Heading, HStack } from "@chakra-ui/react"; import {
import { HelpDrawer, PrettyButton } from "components"; Heading,
HStack,
Menu,
MenuList,
MenuItem,
MenuDivider,
} from "@chakra-ui/react";
import { HelpDrawer, PrettyMenuButton } from "components";
import { intl } from "locale"; import { intl } from "locale";
import { CertificateCreateModal } from "modals"; import { CertificateCreateModal } from "modals";
import { FiGlobe, FiServer, FiUpload } from "react-icons/fi";
import TableWrapper from "./TableWrapper"; import TableWrapper from "./TableWrapper";
function Certificates() { function Certificates() {
const [createShown, setCreateShown] = useState(false); const [createShown, setCreateShown] = useState("");
return ( return (
<> <>
@ -18,15 +26,36 @@ function Certificates() {
</Heading> </Heading>
<HStack> <HStack>
<HelpDrawer section="Certificates" /> <HelpDrawer section="Certificates" />
<PrettyButton size="sm" onClick={() => setCreateShown(true)}> <Menu>
<PrettyMenuButton>
{intl.formatMessage({ id: "certificate.create" })} {intl.formatMessage({ id: "certificate.create" })}
</PrettyButton> </PrettyMenuButton>
<MenuList>
<MenuItem
icon={<FiGlobe />}
onClick={() => setCreateShown("http")}>
{intl.formatMessage({ id: "type.http" })}
</MenuItem>
<MenuItem
icon={<FiServer />}
onClick={() => setCreateShown("dns")}>
{intl.formatMessage({ id: "type.dns" })}
</MenuItem>
<MenuDivider />
<MenuItem
icon={<FiUpload />}
onClick={() => setCreateShown("custom")}>
{intl.formatMessage({ id: "type.custom" })}
</MenuItem>
</MenuList>
</Menu>
</HStack> </HStack>
</HStack> </HStack>
<TableWrapper onCreateClick={() => setCreateShown(true)} /> <TableWrapper />
<CertificateCreateModal <CertificateCreateModal
isOpen={createShown} isOpen={createShown !== ""}
onClose={() => setCreateShown(false)} certType={createShown}
onClose={() => setCreateShown("")}
/> />
</> </>
); );