forked from labring/laf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(web): support setting custom domain for application (labring#1338)
* feat(web): add custom domain * fix(web): fix darkmode
- Loading branch information
1 parent
124b919
commit f3d6845
Showing
12 changed files
with
285 additions
and
18 deletions.
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
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
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
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
116 changes: 116 additions & 0 deletions
116
web/src/pages/app/functions/mods/EditorPanel/EditDomain.tsx
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,116 @@ | ||
import React from "react"; | ||
import { useForm } from "react-hook-form"; | ||
import { | ||
Button, | ||
FormControl, | ||
FormLabel, | ||
Input, | ||
InputGroup, | ||
InputRightAddon, | ||
Modal, | ||
ModalBody, | ||
ModalCloseButton, | ||
ModalContent, | ||
ModalFooter, | ||
ModalHeader, | ||
ModalOverlay, | ||
Tooltip, | ||
useDisclosure, | ||
} from "@chakra-ui/react"; | ||
import { t } from "i18next"; | ||
|
||
import CopyText from "@/components/CopyText"; | ||
|
||
import { useBindDomainMutation, useRemoveApplicationMutation } from "../../service"; | ||
|
||
import useGlobalStore from "@/pages/globalStore"; | ||
|
||
export default function EditDomain(props: { children: any }) { | ||
const { children } = props; | ||
const { isOpen, onOpen, onClose } = useDisclosure(); | ||
const { currentApp, showSuccess, setCurrentApp } = useGlobalStore(); | ||
|
||
const { register, handleSubmit, reset } = useForm<{ domain: string }>({ | ||
defaultValues: { domain: currentApp?.domain.customDomain || "" }, | ||
}); | ||
|
||
const bindDomainMutation = useBindDomainMutation(); | ||
const removeDomainMutation = useRemoveApplicationMutation(); | ||
|
||
return ( | ||
<> | ||
<Tooltip label={t("Edit")}> | ||
{React.cloneElement(children, { | ||
onClick: (event?: any) => { | ||
event?.preventDefault(); | ||
reset({ domain: currentApp?.domain.customDomain || "" }); | ||
onOpen(); | ||
}, | ||
})} | ||
</Tooltip> | ||
|
||
<Modal isOpen={isOpen} onClose={onClose}> | ||
<ModalOverlay /> | ||
<ModalContent> | ||
<ModalHeader>{t("StoragePanel.CustomDomain")}</ModalHeader> | ||
<ModalCloseButton /> | ||
<ModalBody> | ||
<FormControl> | ||
<FormLabel>CNAME</FormLabel> | ||
<InputGroup> | ||
<Input variant="filled" value={currentApp?.domain.domain} readOnly /> | ||
<InputRightAddon | ||
children={ | ||
<CopyText text={currentApp?.domain.domain} className="cursor-pointer" /> | ||
} | ||
/> | ||
</InputGroup> | ||
</FormControl> | ||
<FormControl> | ||
<FormLabel htmlFor="domain">{t("StoragePanel.domain")}</FormLabel> | ||
<Input | ||
{...register("domain", { | ||
required: true, | ||
})} | ||
variant="filled" | ||
placeholder={String(t("StoragePanel.domainTip"))} | ||
/> | ||
</FormControl> | ||
</ModalBody> | ||
<ModalFooter> | ||
<Button | ||
variant={"warn"} | ||
onClick={async () => { | ||
const res: any = await removeDomainMutation.mutateAsync({}); | ||
if (res.data) { | ||
onClose(); | ||
setCurrentApp({ ...currentApp, domain: res.data }); | ||
showSuccess(t("StoragePanel.DomainDeleteSuccess")); | ||
} | ||
}} | ||
className="mr-4" | ||
> | ||
{t("Delete")} | ||
</Button> | ||
<Button | ||
type="submit" | ||
isLoading={bindDomainMutation.isLoading} | ||
onClick={handleSubmit(async (value) => { | ||
const res: any = await bindDomainMutation.mutateAsync({ | ||
domain: value.domain, | ||
}); | ||
if (res.data) { | ||
onClose(); | ||
setCurrentApp({ ...currentApp, domain: res.data }); | ||
showSuccess(t("StoragePanel.DomainUpdateSuccess")); | ||
} | ||
})} | ||
> | ||
{t("Confirm")} | ||
</Button> | ||
</ModalFooter> | ||
</ModalContent> | ||
</Modal> | ||
</> | ||
); | ||
} |
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
Oops, something went wrong.