import React, { Suspense, useEffect, useState, useRef, lazy } from 'react'; import { Meteor } from 'meteor/meteor';; import { NecessitatsCollection } from '/imports/api/necessitats.js'; import { PoblesCollection } from '../api/pobles'; import { TipusCollection } from '../api/tipus'; import { useSubscribe, useTracker, useFind } from 'meteor/react-meteor-data/suspense'; import { Roles } from 'meteor/roles'; // import { useUserId } from 'meteor/react-meteor-accounts'; // import Select from 'react-select' import CreatableSelect from 'react-select/creatable'; import AsyncCreatableSelect from 'react-select/async-creatable'; import { BarraNav } from "./BarraNav/BarraNav"; export const Necessitats = () => { // const [permes, setPermes] = useState(false); const [esEditor, setEsEditor] = useState(false); const userId = Meteor.userId(); useEffect(() => { (async () => { const comprovaAdmin = await Roles.userIsInRoleAsync(userId, ["admin"]); setEsEditor(comprovaAdmin); })(); }, []); // console.log("isAdmin: ", isAdmin) ; const [necessitatSeleccionada, setNecessitatSeleccionada] = useState(null); useSubscribe('necessitats'); const necessitats = useTracker("necessitats", () => NecessitatsCollection.find().fetchAsync()); useSubscribe('pobles'); const pobles = useTracker("pobles", () => PoblesCollection.find().fetchAsync()); useSubscribe('tipus'); const tipus = useTracker("tipus", () => TipusCollection.find().fetchAsync()); const QuadreInfo_Necessitats = () => { return
{necessitatSeleccionada &&

{necessitatSeleccionada._id}

}

Necessitats

{ if (d.get('selTipus')) try { Meteor.callAsync('afigNecessitat', { ...necessitatSeleccionada || [], titol: d.get('titol'), tipus: d.get('selTipus') || "", poble: d.get('selPoble') }) .then(() => setNecessitatSeleccionada(null)) .catch(err => console.error(err)) ; } catch (err) { alert(err); console.error(err); } }} >


{/* Si l'usuari és ADMINISTRADOR o té permisos de responsabilitat, podrà crear nous Tipus al CREAR o a l'EDITAR si no tansols podrà assignar a un tipus predefinit o al de ALTRES */} "Crear nou tipus..."} defaultOptions={tipus.map((v,i) => ({value: v._id, label: v.titol})).sort((a,b) => a.label.toLowerCase() > b.label.toLowerCase()) } onCreateOption={(inputValue) => Meteor.callAsync('afigTipus', {titol: inputValue})} // loadOptions={tipus.map((v,i) => ({value: v, label: v.titol}))} /> {/* */}
({value: v._id, label: v.nomPoble})) } /> {/* */}



Contacte




{necessitatSeleccionada && esEditor && }
; }; return Carregant...} >

; };