import React, { Suspense, useEffect, useState, useRef, lazy } from 'react'; import { Meteor } from 'meteor/meteor'; import { PoblesCollection } from '/imports/api/pobles.js'; import { useSubscribe, useTracker, useFind } from 'meteor/react-meteor-data/suspense'; import { Roles } from 'meteor/roles'; // import { useUserId } from 'meteor/react-meteor-accounts'; // import { Meteor } from 'meteor/meteor'; // import React, {useState, useEffect, Suspense} from 'react'; // import { useTracker, useFind } from 'meteor/react-meteor-data/suspense'; // import { FilesCol } from '/imports/api/files.js'; import { useNavigate, Link } from 'react-router-dom'; // import { Roles } from 'meteor/roles'; // import { useUserContext } from '/imports/api/contexts/AppContext'; // import { groupBy } from 'lodash'; //import Radium from 'radium'; // const IndicadorMissatges = ({notif}) => { // return // {notif && } // // ; // }; const U = ({u, esAdministrador, setUsrSeleccionat}) => { const [adm, setAdm] = useState(false); const [mon, setMon] = useState(false); const [enc, setEnc] = useState(false); const [vol, setVol] = useState(false); (async () => { const esAdmin = await Roles.userIsInRoleAsync(u._id, ["admin"]); setAdm(esAdmin); const esMonit = await Roles.userIsInRoleAsync(u._id, ["monitor_de_poble"], {anyScope: true}); setMon(esMonit); const esEncar = await Roles.userIsInRoleAsync(u._id, ["encarregat_de_tasques"], {anyScope: true}); setEnc(esEncar); const esVolun = await Roles.userIsInRoleAsync(u._id, ["voluntari_de_poble"], {anyScope: true}); setVol(esVolun); // setEsAdministrador(comprovaAdmin); })(); // console.log("adm: ", adm); // console.log("mon: ", mon); // console.log("enc: ", enc); // console.log("vol: ", vol); // const [esAdministrador, setEsAdministrador] = useState(false); // const u = useTracker("user", async () => await Meteor.userAsync()); // const userId = Meteor.userId(); // useEffect(() => { // (async () => { // const comprovaAdmin = await Roles.userIsInRoleAsync(userId, ["admin"]); // setEsAdministrador(comprovaAdmin); // })(); // }, [Meteor.userId()]); // const u = useUserContext(); // console.log("UUU: ", u); const navigate = useNavigate(); // const files = useTracker(() => { // const filesHandle = Meteor.subscribe('files.avatar'); // // const docsReadyYet = filesHandle.ready(); // const files = FilesCol?.find({"meta.userId": Meteor.userId()}, {sort: {name: 1}}).fetch(); // Meteor.userId() ?? "nop" // return files; // }); // const uname = useTracker(() => Meteor.user({ fields: { 'username': 1 } })?.username ); // const [mostraMenu, setMostraMenu] = useState(false); //const avatarLink = u.avatarLink; // alert("avLnk: ", u.profile.avatarLink); return
{ // setMostraMenu(true); // }} // title="Logout" onClick={ev => { ev.stopPropagation(); ev.preventDefault(); // console.log("u: ", u); navigate(`/${u.username}`); }} >
{ (u && adm) &&
ADMIN
} { (u && mon) &&
mon
} { (u && enc) &&
enc
} { (u && vol) &&
vol
}
{u?.username} { ev.preventDefault(); ev.stopPropagation(); // alert("Click en missatges"); }} > {} {/* */}
{ // mostraMenu && //
{ // // setMostraMenu(false);p // // }} // > // {/* */} //
{ // //setEditaPerfil(true); // ev.stopPropagation(); // ev.preventDefault(); // navigate(`/c/config`); // }} // >Configuración
// {/* */} //
{ // Meteor.logout(err => { // err && alert(`Problema: ${err}`); // }); // navigate(`/`); // }} // >Cierra la sesión
//
}

; }; const AssignadorDeRols = ({pobles, esEditor, rols, usrSeleccionat, ambitsUSel}) => { const [creantRol, setCreantRol] = useState(false); const [ambitGeneral, setAmbitGeneral] = useState(false); // const [ambitsUSel, setAmbitsUSel] = useState([]); // let ambitsUSel; // let ambitsUSel = []; // useEffect(() => { // (async () => { // const ambits = await Roles.getScopesForUserAsync(usrSeleccionat?._id); // // console.log("ambitsUSel: ", ambitsUSel); // // ambitsUSel = ambits; // // setAmbitsUSel(ambits); // ambitsUSel = ambits; // // console.log("ambitsUSel: ", ambitsUSel); // })(); // }, []); return

Rols

Àmbits

General:
    { rols?.map(uRol =>
  • {uRol} {esEditor && }
  • ) }
{/*
    */} { ambitsUSel.map(async aus => { console.log("usrSeleccionat: ", usrSeleccionat); console.log("ambitsUSel: ", ambitsUSel); const uRol = await Roles.getRolesForUserAsync(usrSeleccionat._id, {scope: aus, onlyScoped: true}); return <>
    {aus}:
    { {uRol} {esEditor && } }
    ; }) } {/*
*/} {esEditor && creantRol &&
{ if (ambitGeneral) { Meteor.callAsync('assignaRol', usrSeleccionat._id, d.get('selRol')); } else { Meteor.callAsync('assignaRol', usrSeleccionat._id, d.get('selRol'), d.get('selAmbit')); } }}> Àmbit:
Rol:

} {esEditor && usrSeleccionat && }
; }; const QuadreInfo_Usuari = ({usrSeleccionat, esEditor, pobles, rols, ambitsUSel}) => { return
{usrSeleccionat &&

{usrSeleccionat._id}

}
{ try { Meteor.callAsync('editaOAfigPoble', { ...usrSeleccionat || [], nomPoble: d.get('nomPoble'), cp: d.get('cp') || "", comarca: d.get('comarca') || "", }).then(() => setUsrSeleccionat(null)) .catch(err => console.error(err)); } catch (err) { alert(err); console.error(err); } }} >


{ esEditor && }
; }; export const Usuaris = () => { const [usrSeleccionat, setUsrSeleccionat] = useState(null); useSubscribe('pobles'); const pobles = useTracker("pobles", () => PoblesCollection.find().fetchAsync()); const [esEditor, setEsEditor] = useState(false); const userId = Meteor.userId(); const usuaris = useTracker("usuaris", () => { Meteor.subscribe('usuaris'); return Meteor.users.find().fetch();//.filter(u => u._id !== Meteor.userId()); }); // console.log("isAdmin: ", isAdmin) ; console.log("usuaris: ", usuaris); // const [ambitsUSel, setAmbitsUSel] = useState([]); // (async () => { // let ambitsUSel = []; useEffect(() => { (async () => { const comprovaAdmin = await Roles.userIsInRoleAsync(userId, ["admin"]); setEsEditor(comprovaAdmin); // console.log("ambitsUSel: ", ambitsUSel); })(); }, []); const ambitsUSel = Roles.getScopesForUser(usrSeleccionat?._id); // setAmbitsUSel(ambits); const rols = useTracker("rols", async () => { return await Roles.getRolesForUserAsync(usrSeleccionat?._id); }); // })(); // const [monitors, setMonitors] = useState(false); // const [encarregats, setEncarregats] = useState(false); // const [voluntaris, setVoluntaris] = useState(false); // const [administradors, setAdministradors] = useState(false); // let mon, mons, enc, encs, vol, vols; // let // administradors, // monitors, // encarregats, // voluntaris // ; // (async () => { // const admins = await Roles.getUsersInRoleAsync("administrador"); // // console.log("admins: ", admins); // administradors = await admins?.fetchAsync(); // console.log("administradors: ", administradors); // const mons = await Roles.getUsersInRoleAsync("monitor_de_poble"); // // console.log("mons: ", mons); // monitors = await mons?.fetchAsync(); // console.log("monitors: ", monitors); // const encs = await Roles.getUsersInRoleAsync("encarregat_de_tasques"); // // console.log("encs: ", encs); // encarregats = await encs?.fetchAsync(); // console.log("encarregats: ", encarregats); // const vols = await Roles.getUsersInRoleAsync("voluntari_de_poble"); // // console.log("vols: ", vols); // voluntaris = await vols?.fetchAsync(); // console.log("voluntaris: ", voluntaris); // })(); return Carregant...} >

Usuaris

{ esEditor && }
    { usuaris .sort((a,b) => a.username?.toLowerCase() > b.username?.toLowerCase()) .map(usr =>
  • {/* {usr.username}{esEditor && } */}
  • ) }
; };