import React, { FC, useState } from "react"; import styled from "styled-components"; import { Flex } from "reflexbox/styled-components"; import { useStoreState, useStoreActions } from "../../store"; import { useFormState } from "react-use-form-state"; import { useMessage } from "../../hooks"; import TextInput from "../TextInput"; import Button from "../Button"; import Text from "../Text"; // TODO: types interface Props { settings: { customDomain: string; domainInput: boolean; homepage: string; }; handleCustomDomain: any; loading: boolean; showDomainInput: any; showModal: any; } const ButtonWrapper = styled(Flex).attrs({ justifyContent: ["column", "column", "row"], alignItems: ["flex-start", "flex-start", "center"], my: 32 })` display: flex; button { margin-right: 16px; } @media only screen and (max-width: 768px) { > * { margin: 8px 0; } } `; const Domain = styled.h4` margin: 0 16px 0 0; font-size: 20px; font-weight: bold; span { border-bottom: 2px dotted #999; } `; const Homepage = styled.h6` margin: 0 16px 0 0; font-size: 14px; font-weight: 300; span { border-bottom: 2px dotted #999; } `; const SettingsDomain: FC = ({ showDomainInput, showModal }) => { const [loading, setLoading] = useState(false); const [message, setMessage] = useMessage(2000); const domains = useStoreState(s => s.settings.domains); const { saveDomain } = useStoreActions(s => s.settings); const [formState, { text }] = useFormState<{ customDomain: string; homepage: string; }>(); const onSubmit = async e => { e.preventDefault(); setLoading(true); try { await saveDomain(formState.values); } catch (err) { setMessage(err?.response?.data?.error || "Couldn't add domain."); } setLoading(false); }; return ( Custom domain You can set a custom domain for your short URLs, so instead of{" "} kutt.it/shorturl you can have example.com/shorturl. Point your domain A record to 192.64.116.170 then add the domain via form below: {domains.length ? ( domains.map(d => ( {d.customDomain} (Homepage redirects to{" "} {d.homepage || window.location.hostname}) )) ) : ( Domain Homepage (optional) )} {message.text} ); }; export default SettingsDomain;