import { Box, Button, CheckIcon, EditIcon, Flex, FlexProps, IconButton, Modal, ModalBody, ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalOverlay, Text, useDisclosure, } from '@metafam/ds'; import { Maybe } from '@metafam/utils'; import React, { useCallback } from 'react'; import { SetupPersonalityType } from '#components/Setup/SetupPersonalityType'; import { SetupPlayerLinks } from '#components/Setup/SetupPlayerLinks'; import { SetupPlayerType } from '#components/Setup/SetupPlayerType'; import { EditRoles } from '#components/Setup/SetupRoles'; import { EditSkills } from '#components/Setup/SetupSkills'; import { usePlayerHydrationContext } from '#contexts/PlayerHydrationContext'; import { BoxType, BoxTypes } from '#utils/boxTypes'; import { SetupDeworkLink } from '../Setup/SetupDeworkURL'; export type ProfileSectionProps = { children?: React.ReactNode; isOwnProfile?: Maybe; editing?: boolean; type?: BoxType; title?: string | false; modalPrompt?: string; modalTitle?: string | false; modal?: React.ReactNode; subheader?: string; connected?: boolean; }; export const ProfileSection: React.FC< ProfileSectionProps & Omit > = ({ children, isOwnProfile, editing, type: boxType, title = false, modalPrompt, modal, modalTitle, subheader, connected, ...props }) => { const { isOpen, onOpen, onClose } = useDisclosure(); return ( {connected && ( Wallet connected )} {title !== false && ( {title && ( {title} )} {isOwnProfile && !editing && isEditable(boxType) && ( } _hover={{ color: 'white' }} _focus={{ boxShadow: 'none' }} _active={{ transform: 'scale(0.8)' }} isRound mr={-4} onClick={onOpen} /> )} {modal && modalPrompt && ( )} )} {children} {(boxType || modal) && ( {modalTitle !== false && ( {modalTitle ?? title} {subheader && ( {subheader} )} )} {modal ?? } {/* we should figure out how to unify modal footers (edit sections have their own, look into EditSectionBox components - they have footers with 'save' and 'cancel' buttons) */} {modal && ( )} )} ); }; const isEditable = (type?: Maybe) => !!type && ( [ BoxTypes.DEWORK, BoxTypes.PLAYER_TYPE, BoxTypes.PLAYER_COLOR_DISPOSITION, BoxTypes.PLAYER_SKILLS, BoxTypes.PLAYER_ROLES, BoxTypes.PLAYER_LINKS, ] as Array ).includes(type); const EditSection = ({ boxType, onClose, }: { boxType?: string; onClose: () => void; }) => { const buttonLabel = 'Save'; const { hydrateFromComposeDB: performComposeDBHydration, hydrateFromHasura: performHasuraHydration, hydratedPlayer, } = usePlayerHydrationContext(); const hydrateFromComposeDB = useCallback( async (nodeId?: string) => { if (nodeId) { await performComposeDBHydration(nodeId); } onClose(); }, [onClose, performComposeDBHydration], ); const hydrateFromHasura = useCallback(async () => { await performHasuraHydration(); onClose(); }, [onClose, performHasuraHydration]); switch (boxType) { case BoxTypes.PLAYER_TYPE: { return ( ); } case BoxTypes.PLAYER_COLOR_DISPOSITION: { return ( ); } case BoxTypes.PLAYER_SKILLS: { return ( ); } case BoxTypes.PLAYER_ROLES: { return ( ); } case BoxTypes.DEWORK: { return ( ); } case BoxTypes.PLAYER_LINKS: { return ( ); } default: } return <>; };