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 Tipus = () => { // 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 [tipusSeleccionat, setNecessitatSeleccionat] = 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()); // console.log("tipus: ", tipus); // console.log("necessitats: ", necessitats); // console.log("tipusSeleccionat: ", tipusSeleccionat); const filterTipus = (inputValue) => { return tipus.filter((i) => i.titol.toLowerCase().includes(inputValue.toLowerCase()) ); }; const QuadreInfo_Tipus = () => { return
{tipusSeleccionat &&

{tipusSeleccionat._id}

}

Tipus

{ if (d.get('selTipus')) try { Meteor.callAsync('editaOAfigNecessitat', { ...tipusSeleccionat || [], titol: d.get('titol'), tipus: d.get('selTipus') || "", poble: d.get('selPoble') }) .then(() => setTipusSeleccionat(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})} isSearchable // loadOptions={tipus.map((v,i) => ({value: v, label: v.titol}))} /> {/* */}


({value: v._id, label: v.nomPoble})) } /> {/* */}
{tipusSeleccionat && esEditor && }
; }; return Carregant...} >

{/* ({value: v, label: v.titol})) } loadOptions={tipus.map((v,i) => ({value: v, label: v.titol}))} /> */} {/* */}
    { tipus .sort((a,b) => a.titol?.toLowerCase() > b.titol?.toLowerCase()) .map(titol =>
  • {titol.titol}{esEditor && }
  • ) }
; };