From 3dac3953e5c4ba2c964078f13b4123ee7c05cab3 Mon Sep 17 00:00:00 2001 From: "riho.takagi" Date: Mon, 6 Nov 2023 18:37:48 -0500 Subject: [PATCH] Add loading component --- .../admin-page/components/AdminUsers.tsx | 10 ++++++++ .../src/client/admin-page/components/Ban.tsx | 9 ++++++++ .../client/admin-page/components/Liaisons.tsx | 9 ++++++++ .../admin-page/components/SafetyTraining.tsx | 9 ++++++++ .../client/booking/components/FormInput.tsx | 2 ++ .../client/booking/components/SheetEditor.tsx | 5 +++- .../src/client/utils/Loading.tsx | 23 +++++++++++++++++++ 7 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 media_commons_booking_app/src/client/utils/Loading.tsx diff --git a/media_commons_booking_app/src/client/admin-page/components/AdminUsers.tsx b/media_commons_booking_app/src/client/admin-page/components/AdminUsers.tsx index 4600739b..9fe10906 100644 --- a/media_commons_booking_app/src/client/admin-page/components/AdminUsers.tsx +++ b/media_commons_booking_app/src/client/admin-page/components/AdminUsers.tsx @@ -3,6 +3,7 @@ import React, { useState, useEffect } from 'react'; // This is a wrapper for google.script.run that lets us use promises. import { serverFunctions } from '../../utils/serverFunctions'; import { formatDate } from '../../utils/date'; +import { Loading } from '../../utils/Loading'; const ADMIN_USER_SHEET_NAME = 'admin_users'; @@ -50,6 +51,8 @@ export const AdminUsers = () => { }; const addAdminUser = async () => { + setLoading(true); + if (adminEmails.includes(email)) { alert('This user is already registered'); return; @@ -61,8 +64,13 @@ export const AdminUsers = () => { ]); alert('User has been registered successfully!'); + setLoading(false); fetchAdminUsers(); }; + const [loading, setLoading] = useState(false); + if (loading) { + return ; + } return (
@@ -125,12 +133,14 @@ export const AdminUsers = () => {
diff --git a/media_commons_booking_app/src/client/booking/components/SheetEditor.tsx b/media_commons_booking_app/src/client/booking/components/SheetEditor.tsx index 3f72807f..a8a0dd51 100644 --- a/media_commons_booking_app/src/client/booking/components/SheetEditor.tsx +++ b/media_commons_booking_app/src/client/booking/components/SheetEditor.tsx @@ -9,6 +9,7 @@ import { Header } from './Header'; import { MultipleCalendars } from './MultipleCalendars'; import { Modal } from 'react-bootstrap'; import { InitialModal } from './InitialModal'; +import { Loading } from '../../utils/Loading'; export type RoomSetting = { roomId: string; name: string; @@ -199,10 +200,12 @@ const SheetEditor = () => { alert( "Your request has been sent.\n Please check the calendar to verify that your submitted event has been registered.\n If you don't see the event, please contact us." ); + setLoading(false); setSection('selectRoom'); }); }; const handleSubmit = async (data) => { + setLoading(true); if (!bookInfo) return; if (!userEmail && data.missingEmail) { setUserEmail(data.missingEmail); @@ -273,7 +276,7 @@ const SheetEditor = () => { }; if (loading) { - return
Loading...
; + return ; } const handleModalClick = () => { diff --git a/media_commons_booking_app/src/client/utils/Loading.tsx b/media_commons_booking_app/src/client/utils/Loading.tsx new file mode 100644 index 00000000..d275157c --- /dev/null +++ b/media_commons_booking_app/src/client/utils/Loading.tsx @@ -0,0 +1,23 @@ +import React from 'react'; + +export const Loading = () => ( +
+ + Loading... +
+);