changed ItemFormPopup

This commit is contained in:
Anton 2023-12-24 03:02:06 +01:00
parent 38aeb28fab
commit 4efa682b06
2 changed files with 7 additions and 4 deletions

View File

@ -11,6 +11,7 @@ import { useResetFilterTags } from '../hooks/useFilter'
import { hashTagRegex } from '../../../Utils/HashTagRegex'
import { randomColor } from '../../../Utils/RandomColor'
import { useAddTag, useTags } from '../hooks/useTags'
import { useAuth } from '../../Auth'
export interface ItemFormPopupProps {
position: LatLng,
@ -36,6 +37,8 @@ export function ItemFormPopup(props: ItemFormPopupProps) {
const resetFilterTags = useResetFilterTags();
const { user } = useAuth();
const handleSubmit = async (evt: any) => {
const formItem: Item = {} as Item;
@ -76,13 +79,13 @@ export function ItemFormPopup(props: ItemFormPopupProps) {
let success = false;
try {
await props.layer.api?.createItem!({...formItem, id: crypto.randomUUID()});
await props.layer.api?.createItem!({...formItem, id: crypto.randomUUID() });
success = true;
} catch (error) {
toast.error(error.toString());
}
if(success) {
addItem({...formItem, id: crypto.randomUUID(), layer: props.layer});
addItem({...formItem, id: crypto.randomUUID(), layer: props.layer, user_created: user});
toast.success("New item created");
resetFilterTags();
}
@ -118,7 +121,6 @@ export function ItemFormPopup(props: ItemFormPopupProps) {
:
<div className='tw-flex tw-justify-center'><b className="tw-text-xl tw-font-bold">New {props.layer.name}</b></div>
}
<TextInput type="text" placeholder="Name" dataField="name" defaultValue={props.item ? props.item.name : ""} inputStyle='' />
{props.children ?
@ -129,6 +131,7 @@ export function ItemFormPopup(props: ItemFormPopupProps) {
:
<>
<TextInput type="text" placeholder="Name" dataField="name" defaultValue={props.item ? props.item.name : ""} inputStyle='' />
<TextAreaInput key={props.position.toString()} placeholder="Text" dataField="text" defaultValue={props.item ? props.item.text : ""} inputStyle='tw-h-40 tw-mt-5' />
</>
}

View File

@ -11,6 +11,6 @@ export const PopupTextInput = ({ dataField, placeholder, style, item }:
}) => {
return (
<TextInput defaultValue={item?.text ? item.text : ""} dataField={dataField} placeholder={placeholder} inputStyle={style}></TextInput>
<TextInput defaultValue={item?.text ? item.text : ""} dataField={dataField} placeholder={placeholder} inputStyle={style} type='text'></TextInput>
)
}