import { ClassroomRegistrationUser } from "../types/ClassroomRegistrationUser"; import { QuestionIcon } from "../icons/QuestionIcon"; import { JsonResult } from "../types/JsonResult"; import { XcircleIcon } from "../icons/XCircleIcon"; import { LoadingStatus, backend, useLoading, wait } from "../utils/functions"; import { LinkIcon } from "../icons/LinkIcon"; import { For, Show, createSignal, onMount } from "solid-js"; import { LoadingIcon } from "../icons/LoadingIcon"; type Status = "Init" | "Ok" | "Loading" | "Error"; export function ClassroomVinculation(props: {person_surname: string, personId: number, onLink: (classroom_id: number) => void,}) { const [classroomUsers, setClassroomUsers] = createSignal([]); const [error, setError] = createSignal(""); const [status, setStatus] = createSignal("Init"); const loadUsers = async() => { setStatus("Loading"); const response = await fetch(`${import.meta.env.VITE_BACKEND_URL}/api/classroom/users/${encodeURIComponent(props.person_surname)}`); const json: JsonResult> = await response.json(); if (response.ok) { setClassroomUsers(json.Ok); setStatus("Ok"); } else { console.error("Error loading users", json); setError(json.Err.reason); setStatus("Error"); } }; onMount(loadUsers); return (

Vincule un usuario existente:

No se encontraron usuarios en el aula virtual.

{(u) => ( )}

Error buscando usuarios: {error()}.

); } function ClassroomSingleUser(props: { user: ClassroomRegistrationUser, onLink: (classroom_id: number) => void, personId: number, }) { const {setError, status, setStatus} = useLoading(); const linkUser = async() => { setStatus(LoadingStatus.Loading); if (import.meta.env.DEV) await wait(1500); backend.put>( "/api/person/link", { person_id: props.personId, person_classroom_id: parseInt(props.user.user_id, 10), }, ) .then((response) => { if (response.status === 200) { setStatus(LoadingStatus.Ok); props.onLink(parseInt(props.user.user_id, 10)); } else { console.error(response.data); setError(response.data.Err.reason); setStatus(LoadingStatus.Error); } }) .catch((err) => { setError(`Error fatal: ${err.message}`); console.error(err); setStatus(LoadingStatus.Error); }); }; return (
{props.user.name} {props.user.surname}
{props.user.username}
registrado:  ??/??/????
); }