import React, { useState, useEffect } from "react"; import { useSubscriptions } from "../core/hooks"; import { Input, Stack, Text, HStack, useRadioGroup, FormControl, FormErrorMessage, ModalBody, ModalCloseButton, ModalHeader, Button, ModalFooter, Spinner, IconButton, } from "@chakra-ui/react"; import RadioCard from "./RadioCard"; import { useForm } from "react-hook-form"; import { GithubPicker } from "react-color"; import { BiRefresh } from "react-icons/bi"; import { makeColor } from "../core/utils/makeColor"; const NewSubscription = ({ isFreeOption, onClose }) => { const [color, setColor] = useState(makeColor()); const { typesCache, createSubscription } = useSubscriptions(); const { handleSubmit, errors, register } = useForm({}); const [radioState, setRadioState] = useState("ethereum_blockchain"); let { getRootProps, getRadioProps } = useRadioGroup({ name: "type", defaultValue: radioState, onChange: setRadioState, }); const group = getRootProps(); useEffect(() => { if (createSubscription.isSuccess) { onClose(); } }, [createSubscription.isSuccess, onClose]); if (typesCache.isLoading) return ; const createSubscriptionWrap = (props) => { createSubscription.mutate({ ...props, color: color, type: isFreeOption ? "free" : radioState, }); }; const handleChangeColorComplete = (color) => { setColor(color.hex); }; return (
Subscribe to a new address {errors.label && errors.label.message} {errors.address && errors.address.message} {isFreeOption ? `Free subscription is only availible Ethereum blockchain source` : `On which source?`} {typesCache.data.subscriptions.map((type) => { const radio = getRadioProps({ value: type.id, isDisabled: !type.active || (isFreeOption && type.subscription_type !== "ethereum_blockchain"), }); return ( {type.name} ); })} null} > {errors.subscription_type && errors.subscription_type.message} Label color {" "} setColor(makeColor())} icon={} /> null} w="200px" > {errors.color && errors.color.message} ); }; export default NewSubscription;