/* eslint-disable @typescript-eslint/restrict-template-expressions */ import { useRef, useState, useEffect } from 'react' import { useNavigate } from 'react-router-dom' import { toast } from 'react-toastify' import { useAppState } from '#components/AppShell/hooks/useAppState' import { useItems } from '#components/Map/hooks/useItems' import { Item, ItemsApi } from '#src/types' import { EmojiPicker } from './EmojiPicker' import { MapOverlayPage } from './MapOverlayPage' export const AttestationForm = ({ api }: { api?: ItemsApi }) => { const items = useItems() const appState = useAppState() const [users, setUsers] = useState() const navigate = useNavigate() useEffect(() => { const params = new URLSearchParams(location.search) const toUserIds = params.get('to') setUsers(items.filter((i) => toUserIds?.includes(i.id))) // eslint-disable-next-line react-hooks/exhaustive-deps }, [items, location]) const [inputValue, setInputValue] = useState('') const inputRef = useRef(null) useEffect(() => { if (inputRef.current) { inputRef.current.style.width = 'auto' inputRef.current.style.width = `${inputRef.current.scrollWidth + 20}px` } }, [inputValue]) const handleChange = (event: React.ChangeEvent) => { setInputValue(event.target.value) } const sendAttestation = async () => { const to: any[] = [] users?.map((u) => to.push({ directus_users_id: u.user_created.id })) api?.createItem && toast .promise( api.createItem({ text: inputValue, emoji: selectedEmoji, color: selectedColor, shape: selectedShape, to, }), { pending: 'creating attestation ...', success: 'Attestation created', error: { render({ data }) { return `${data}` }, }, }, ) .then(() => navigate( '/item/' + items.find( (i) => i.user_created.id === to[0].directus_users_id && i.layer?.itemType.name === 'player', )?.id + '?tab=2', ), ) } const [selectedEmoji, setSelectedEmoji] = useState('select badge') const [selectedShape, setSelectedShape] = useState('circle') const [selectedColor, setSelectedColor] = useState('#fff0d6') return (
Gratitude
to
{users && users.map( (u, k) => (
{u.image ? (
Avatar
) : (
)}
{u.name}
), ', ', )}
) }