[Classroom][BE] Fixes #8 Fix error setting expiration date

This commit is contained in:
Araozu 2023-10-09 09:32:02 -05:00
parent c78dbf479f
commit 5f1a46747a
3 changed files with 20 additions and 7 deletions

View File

@ -52,7 +52,7 @@ pub async fn classroom_post_redirect(
match response.text() { match response.text() {
Ok(t) => { Ok(t) => {
log_html(&t); log_html(&t);
Err(format!("Unexpected response from classroom.")) Err(format!("Expected HTTP 302, got other code."))
} }
Err(err) => Err(format!("Error getting text from response: {:?}", err)), Err(err) => Err(format!("Error getting text from response: {:?}", err)),
} }

View File

@ -68,6 +68,7 @@ pub async fn update_expiration_date(
email.into(), email.into(),
username.into(), username.into(),
new_expiration_date, new_expiration_date,
user_id,
protect_token.into(), protect_token.into(),
) )
}; };
@ -87,6 +88,7 @@ fn get_body(
email: String, email: String,
username: String, username: String,
new_expiration_date: String, new_expiration_date: String,
user_id: i32,
protect_token: String, protect_token: String,
) -> String { ) -> String {
format!( format!(
@ -251,7 +253,7 @@ Content-Disposition: form-data; name="protect_token"
-----------------------------318235432819784070062970146417 -----------------------------318235432819784070062970146417
Content-Disposition: form-data; name="user_id" Content-Disposition: form-data; name="user_id"
2140 {user_id}
-----------------------------318235432819784070062970146417 -----------------------------318235432819784070062970146417
Content-Disposition: form-data; name="MAX_FILE_SIZE" Content-Disposition: form-data; name="MAX_FILE_SIZE"
@ -267,7 +269,7 @@ Content-Disposition: form-data; name="picture_crop_image_base_64"
-----------------------------318235432819784070062970146417 -----------------------------318235432819784070062970146417
Content-Disposition: form-data; name="item_id" Content-Disposition: form-data; name="item_id"
2140 {user_id}
-----------------------------318235432819784070062970146417-- -----------------------------318235432819784070062970146417--
"# "#
) )

View File

@ -4,14 +4,16 @@ import { LoadingStatus, backend, useLoading, wait } from "../../utils/functions"
import { LoadingIcon } from "../../icons/LoadingIcon"; import { LoadingIcon } from "../../icons/LoadingIcon";
import { ArrowsClockwiseIcon } from "../../icons/ArrowsClockwiseIcon"; import { ArrowsClockwiseIcon } from "../../icons/ArrowsClockwiseIcon";
import { JsonResult } from "../../types/JsonResult"; import { JsonResult } from "../../types/JsonResult";
import { AxiosError } from "axios";
export function AccountExpiration(props: {userId: number}) { export function AccountExpiration(props: {userId: number}) {
const [expirationDate, setExpirationDate] = createSignal<string | null>(null); // YYYY-MM-DD const [expirationDate, setExpirationDate] = createSignal<string | null>(null); // YYYY-MM-DD
const {status, setStatus} = useLoading(); const {status, setStatus, error, setError} = useLoading();
const loading = createMemo(() => status() === LoadingStatus.Loading); const loading = createMemo(() => status() === LoadingStatus.Loading);
const loadExpiration = async() => { const loadExpiration = async() => {
setError("");
setStatus(LoadingStatus.Loading); setStatus(LoadingStatus.Loading);
setExpirationDate(null); setExpirationDate(null);
if (import.meta.env.DEV) await wait(1500); if (import.meta.env.DEV) await wait(1500);
@ -25,10 +27,16 @@ export function AccountExpiration(props: {userId: number}) {
setStatus(LoadingStatus.Ok); setStatus(LoadingStatus.Ok);
} }
}) })
.catch((err) => { .catch((err: AxiosError<JsonResult<null>>) => {
console.log(err); console.log(err);
setStatus(LoadingStatus.Error); setStatus(LoadingStatus.Error);
if (err.response?.status === 500) {
setError(`Error: ${err?.response?.data?.Error}`);
} else {
setError("Error estableciendo fecha de expiracion. Revisar consola");
}
}); });
}; };
@ -78,7 +86,10 @@ export function AccountExpiration(props: {userId: number}) {
/> />
</p> </p>
<div class="text-right pt-2"> <div class="pt-2 grid grid-cols-[auto_8.5rem] items-center gap-2">
<span class="text-c-error">
{error()}
</span>
<button <button
class="bg-c-primary text-c-on-primary px-4 py-2 rounded-full cursor-pointer class="bg-c-primary text-c-on-primary px-4 py-2 rounded-full cursor-pointer
disabled:opacity-50 disabled:cursor-not-allowed relative" disabled:opacity-50 disabled:cursor-not-allowed relative"
@ -87,7 +98,7 @@ export function AccountExpiration(props: {userId: number}) {
onclick={setExpiration} onclick={setExpiration}
> >
<span class="mr-6"> <span class="mr-6">
Actualizar expiracion Actualizar
</span> </span>
<span <span
class="absolute top-1 right-2" class="absolute top-1 right-2"