import React, { useState } from 'react' import { useRouter } from 'next/router' import { useSnapshot } from 'valtio' import { useTranslation } from 'next-i18next' import Linkify from 'react-linkify' import classNames from 'classnames' import * as AlertDialog from '@radix-ui/react-alert-dialog' import Button from '~components/Button' import CharLimitedFieldset from '~components/CharLimitedFieldset' import RaidDropdown from '~components/RaidDropdown' import TextFieldset from '~components/TextFieldset' import { appState } from '~utils/appState' import CheckIcon from '~public/icons/Check.svg' import CrossIcon from '~public/icons/Cross.svg' import EditIcon from '~public/icons/Edit.svg' import './index.scss' import Link from 'next/link' import { formatTimeAgo } from '~utils/timeAgo' // Props interface Props { editable: boolean updateCallback: (name?: string, description?: string, raid?: Raid) => void deleteCallback: ( event: React.MouseEvent ) => void } const PartyDetails = (props: Props) => { const { party, raids } = useSnapshot(appState) const { t } = useTranslation('common') const router = useRouter() const locale = router.locale || 'en' const nameInput = React.createRef() const descriptionInput = React.createRef() const [raidSlug, setRaidSlug] = useState('') const readOnlyClasses = classNames({ PartyDetails: true, ReadOnly: true, Visible: !party.detailsVisible, }) const editableClasses = classNames({ PartyDetails: true, Editable: true, Visible: party.detailsVisible, }) const emptyClasses = classNames({ EmptyDetails: true, Visible: !party.detailsVisible, }) const userClass = classNames({ user: true, empty: !party.user, }) const linkClass = classNames({ wind: party && party.element == 1, fire: party && party.element == 2, water: party && party.element == 3, earth: party && party.element == 4, dark: party && party.element == 5, light: party && party.element == 6, }) const [errors, setErrors] = useState<{ [key: string]: string }>({ name: '', description: '', }) function handleInputChange(event: React.ChangeEvent) { event.preventDefault() const { name, value } = event.target let newErrors = errors setErrors(newErrors) } function handleTextAreaChange(event: React.ChangeEvent) { event.preventDefault() const { name, value } = event.target let newErrors = errors setErrors(newErrors) } function toggleDetails() { appState.party.detailsVisible = !appState.party.detailsVisible } function receiveRaid(slug?: string) { if (slug) setRaidSlug(slug) } function updateDetails(event: React.MouseEvent) { const nameValue = nameInput.current?.value const descriptionValue = descriptionInput.current?.value const raid = raids.find((raid) => raid.slug === raidSlug) props.updateCallback(nameValue, descriptionValue, raid) toggleDetails() } const userImage = () => { if (party.user) return ( {party.user.avatar.picture} ) else return
} const userBlock = () => { return (
{userImage()} {party.user ? party.user.username : t('no_user')}
) } const linkedUserBlock = (user: User) => { return ( ) } const linkedRaidBlock = (raid: Raid) => { return ( ) } const deleteButton = () => { if (party.editable) { return ( {t('buttons.delete')} {t('modals.delete_team.title')} {t('modals.delete_team.description')}
{t('modals.delete_team.buttons.cancel')} props.deleteCallback(e)} > {t('modals.delete_team.buttons.confirm')}
) } else { return '' } } const editable = (
{router.pathname !== '/new' ? deleteButton() : ''}
) const readOnly = (

{party.name ? party.name : 'Untitled'}

{party.user ? linkedUserBlock(party.user) : userBlock()} {party.raid ? linkedRaidBlock(party.raid) : ''} {party.created_at != undefined ? ( ) : ( '' )}
{party.editable ? (
{party.description ? (

{party.description}

) : ( '' )}
) const emptyDetails = (
{party.editable ? (