import * as React from 'react' import { MapOverlayPage } from './MapOverlayPage' import { useItems } from '../Map/hooks/useItems' import { useAssetApi } from '../AppShell/hooks/useAssets' import { EmojiPicker } from './EmojiPicker' import { useNavigate } from 'react-router-dom' import { useRef, useState, useEffect } from 'react' import { Item, ItemsApi } from '../../types' import { toast } from 'react-toastify' export const AttestationForm = ({ api }:{api?:ItemsApi}) => { const items = useItems() const assetsApi = useAssetApi() 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 : Array = [] 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}
), ', ')}
) }