[Classroom] Update UI when a classroom user is created
This commit is contained in:
parent
746775b563
commit
968b69dfa6
@ -1,6 +1,6 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
json_result::JsonResult,
|
json_result::JsonResult,
|
||||||
model::classroom_user::{ClassroomPersonCreate, ClassroomCourseRegistration},
|
model::{classroom_user::{ClassroomPersonCreate, ClassroomCourseRegistration}, person::PersonLink},
|
||||||
online_classroom::{create_user::create, get_courses::ClassroomCourse},
|
online_classroom::{create_user::create, get_courses::ClassroomCourse},
|
||||||
};
|
};
|
||||||
use rocket::{http::Status, serde::json::Json};
|
use rocket::{http::Status, serde::json::Json};
|
||||||
@ -12,9 +12,9 @@ pub fn create_user_options() -> Status {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[post("/classroom/user", format = "json", data = "<data>")]
|
#[post("/classroom/user", format = "json", data = "<data>")]
|
||||||
pub async fn create_user(data: Json<ClassroomPersonCreate>) -> (Status, Json<JsonResult<()>>) {
|
pub async fn create_user(data: Json<ClassroomPersonCreate>) -> (Status, Json<JsonResult<PersonLink>>) {
|
||||||
match create(&data.0).await {
|
match create(&data.0).await {
|
||||||
Ok(_) => return (Status::Ok, JsonResult::ok(())),
|
Ok(p) => return (Status::Ok, JsonResult::ok(p)),
|
||||||
Err(err) => return (Status::InternalServerError, JsonResult::err(err)),
|
Err(err) => return (Status::InternalServerError, JsonResult::err(err)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ impl PersonCreate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct PersonLink {
|
pub struct PersonLink {
|
||||||
pub person_id: i32,
|
pub person_id: i32,
|
||||||
pub person_classroom_id: i32,
|
pub person_classroom_id: i32,
|
||||||
|
@ -5,7 +5,7 @@ use scraper::{Html, Selector};
|
|||||||
const CREATION_ERR: &str = "Creation successful, but linking failed";
|
const CREATION_ERR: &str = "Creation successful, but linking failed";
|
||||||
|
|
||||||
/// Creates an online classroom user
|
/// Creates an online classroom user
|
||||||
pub async fn create(data: &ClassroomPersonCreate) -> Result<(), String> {
|
pub async fn create(data: &ClassroomPersonCreate) -> Result<PersonLink, String> {
|
||||||
let sec_token = get_form_sec_token().await?;
|
let sec_token = get_form_sec_token().await?;
|
||||||
|
|
||||||
let body = get_request_body(
|
let body = get_request_body(
|
||||||
@ -35,15 +35,14 @@ pub async fn create(data: &ClassroomPersonCreate) -> Result<(), String> {
|
|||||||
))
|
))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let result = PersonLink {
|
let person_link = PersonLink {
|
||||||
person_id: data.person_id,
|
person_id: data.person_id,
|
||||||
person_classroom_id: user_id,
|
person_classroom_id: user_id,
|
||||||
}
|
};
|
||||||
.insert()
|
let result = person_link.insert().await;
|
||||||
.await;
|
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(_) => return Ok(()),
|
Ok(_) => return Ok(person_link),
|
||||||
Err(reason) => return Err(format!("{}: {}", CREATION_ERR, reason)),
|
Err(reason) => return Err(format!("{}: {}", CREATION_ERR, reason)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,10 @@ export function ClassroomRegistration(props: {
|
|||||||
userId={props.userId}
|
userId={props.userId}
|
||||||
selections={selections()}
|
selections={selections()}
|
||||||
deleteRegister={(course_key) => setSelections((course) => course.filter((v) => v !== course_key))}
|
deleteRegister={(course_key) => setSelections((course) => course.filter((v) => v !== course_key))}
|
||||||
onSuccess={props.onSuccess}
|
onSuccess={() => {
|
||||||
|
setSelections([]);
|
||||||
|
props.onSuccess();
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -7,7 +7,12 @@ import { LoadingStatus, backend, useLoading, wait } from "../utils/functions";
|
|||||||
import { JsonResult } from "../types/JsonResult";
|
import { JsonResult } from "../types/JsonResult";
|
||||||
import { LoadingIcon } from "../icons/LoadingIcon";
|
import { LoadingIcon } from "../icons/LoadingIcon";
|
||||||
|
|
||||||
export function ClassroomUserCreation(props: {person: Person}) {
|
type PersonLink = {
|
||||||
|
person_id: number,
|
||||||
|
person_classroom_id: number,
|
||||||
|
};
|
||||||
|
|
||||||
|
export function ClassroomUserCreation(props: {person: Person, onCreate: (classroom_id: number) => void}) {
|
||||||
const [email, setEmail] = createSignal("yuli.palo.apaza@gmail.com");
|
const [email, setEmail] = createSignal("yuli.palo.apaza@gmail.com");
|
||||||
const [username, setUsername] = createSignal("USERNAME");
|
const [username, setUsername] = createSignal("USERNAME");
|
||||||
const {setError, status, setStatus} = useLoading();
|
const {setError, status, setStatus} = useLoading();
|
||||||
@ -37,7 +42,7 @@ export function ClassroomUserCreation(props: {person: Person}) {
|
|||||||
|
|
||||||
if (import.meta.env.DEV) await wait(1500);
|
if (import.meta.env.DEV) await wait(1500);
|
||||||
|
|
||||||
backend.post<JsonResult<null>>("/api/classroom/user", {
|
backend.post<JsonResult<PersonLink>>("/api/classroom/user", {
|
||||||
person_id: props.person.person_id,
|
person_id: props.person.person_id,
|
||||||
person_names: names(),
|
person_names: names(),
|
||||||
person_surnames: surnames(),
|
person_surnames: surnames(),
|
||||||
@ -50,6 +55,7 @@ export function ClassroomUserCreation(props: {person: Person}) {
|
|||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
alert("Usuario creado con éxito");
|
alert("Usuario creado con éxito");
|
||||||
setStatus(LoadingStatus.Ok);
|
setStatus(LoadingStatus.Ok);
|
||||||
|
props.onCreate(response.data.Ok.person_classroom_id);
|
||||||
} else {
|
} else {
|
||||||
console.error(response.data);
|
console.error(response.data);
|
||||||
setError(response.data.Err.reason);
|
setError(response.data.Err.reason);
|
||||||
|
@ -22,6 +22,7 @@ export function OnlineClassroom() {
|
|||||||
<ClassroomUser
|
<ClassroomUser
|
||||||
person={person()!}
|
person={person()!}
|
||||||
onLink={(classroom_id) => setPerson((p) => ({...p!, person_classroom_id: classroom_id}))}
|
onLink={(classroom_id) => setPerson((p) => ({...p!, person_classroom_id: classroom_id}))}
|
||||||
|
onCreate={(classroom_id) => setPerson((p) => ({...p!, person_classroom_id: classroom_id}))}
|
||||||
/>
|
/>
|
||||||
</Show>
|
</Show>
|
||||||
<Show when={person() !== null && person()!.person_classroom_id !== null}>
|
<Show when={person() !== null && person()!.person_classroom_id !== null}>
|
||||||
@ -43,7 +44,11 @@ export function OnlineClassroom() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
function ClassroomUser(props: {person: Person, onLink: (classroom_id: number) => void,}) {
|
function ClassroomUser(props: {
|
||||||
|
person: Person,
|
||||||
|
onLink: (classroom_id: number) => void,
|
||||||
|
onCreate: (classroom_id: number) => void,
|
||||||
|
}) {
|
||||||
const [active, setActive] = createSignal<TabType>("Vinculate");
|
const [active, setActive] = createSignal<TabType>("Vinculate");
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -63,7 +68,10 @@ function ClassroomUser(props: {person: Person, onLink: (classroom_id: number) =>
|
|||||||
/>
|
/>
|
||||||
</Show>
|
</Show>
|
||||||
<Show when={active() === "Create"}>
|
<Show when={active() === "Create"}>
|
||||||
<ClassroomUserCreation person={props.person} />
|
<ClassroomUserCreation
|
||||||
|
person={props.person}
|
||||||
|
onCreate={props.onCreate}
|
||||||
|
/>
|
||||||
</Show>
|
</Show>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user