import React, { useEffect, useState } from "react"; import { VStack, Box, Text, ButtonGroup, Button, useRadioGroup, Stack, Flex, Switch, HStack, } from "@chakra-ui/react"; import { RadioCardWithAffordance } from "../form/RadioCard"; import { CreateChatStep, ICreateChatModalState, ReadPostType, } from "./CreateChatModal"; interface IPermissionTypeProps { state: ICreateChatModalState; setState: React.Dispatch>; defaultValue: undefined | ReadPostType; permissionType: "read" | "post"; onBack: () => void; onNext: () => void; } export const PermissionType: React.FC = ({ state, setState, defaultValue, permissionType, onBack, onNext, }) => { const isPostPermission = permissionType === "post"; const [selectedOption, setSelectedOption] = useState< undefined | ReadPostType >(defaultValue); const { getRootProps, getRadioProps } = useRadioGroup({ name: "readType", value: defaultValue, onChange: (x) => { setSelectedOption(x as ReadPostType); setState({ ...state, wizardData: { ...state.wizardData, postIsSameAsRead: false, ...(isPostPermission ? { postPermissions: undefined } : { readPermissions: undefined }), }, }); }, }); const group = getRootProps(); useEffect(() => { if (selectedOption) { setState({ ...state, wizardData: { ...state.wizardData, [`${permissionType}Type`]: selectedOption, }, }); } }, [selectedOption, setState]); const handleOnToggleSame = (e: React.ChangeEvent) => { const isChecked = e.target.checked; setSelectedOption(undefined); setState({ ...state, wizardData: { ...state.wizardData, postIsSameAsRead: isChecked, [`${permissionType}Type`]: undefined, ...(isChecked ? { postForm: state.wizardData.readForm as any } : { postForm: undefined }), }, }); }; return ( Set your {permissionType} permissions. How do you want to gate {permissionType}ing messages in your chat? {state.step === CreateChatStep.PostPermissionsType && ( Same as read permissions )} {Object.keys(ReadPostType).map((value) => { const radio = getRadioProps({ value }); return ( //@ts-ignore {value} {value === ReadPostType.Token && `Participants need to hold a certain amount of a token to ${permissionType} messages`} {value === ReadPostType.NFT && `Participants need to hold a NFT from a certain collection to ${permissionType} messages`} ); })} ); };