mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-07-18 16:43:56 -05:00
display spinner when submitting form
This commit is contained in:
parent
4202ed3d7a
commit
61cf6e72b6
4
TODO.md
4
TODO.md
|
|
@ -1,8 +1,10 @@
|
|||
### Before production
|
||||
|
||||
- [ ] Can log in
|
||||
- [x] Can log in
|
||||
- [ ] Can update builds
|
||||
- [ ] Build Analyzer
|
||||
- [ ] Import /analyzer
|
||||
- [ ] Builds link to /analyzer
|
||||
- [ ] Script to parse data from Top 500 .json to the DB
|
||||
- [ ] Top 500 Leaderboards
|
||||
- [ ] Localization
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ import {
|
|||
TITLE_CHARACTER_LIMIT,
|
||||
} from "lib/validators/build";
|
||||
import { GetBuildsByUserData } from "prisma/queries/getBuildsByUser";
|
||||
import { Fragment } from "react";
|
||||
import { Fragment, useState } from "react";
|
||||
import { Controller, useForm } from "react-hook-form";
|
||||
import { mutate } from "swr";
|
||||
import * as z from "zod";
|
||||
|
|
@ -49,6 +49,7 @@ interface Props {
|
|||
type FormData = z.infer<typeof buildSchema>;
|
||||
|
||||
const BuildModal: React.FC<Props> = ({ onClose, build }) => {
|
||||
const [sending, setSending] = useState(false);
|
||||
const [loggedInUser] = useUser();
|
||||
|
||||
const { handleSubmit, errors, register, watch, control } = useForm<FormData>({
|
||||
|
|
@ -82,6 +83,7 @@ const BuildModal: React.FC<Props> = ({ onClose, build }) => {
|
|||
const toast = useToast();
|
||||
|
||||
const onSubmit = async (formData: FormData) => {
|
||||
setSending(true);
|
||||
const mutationData = { ...formData };
|
||||
|
||||
for (const [key, value] of Object.entries(mutationData)) {
|
||||
|
|
@ -92,6 +94,7 @@ const BuildModal: React.FC<Props> = ({ onClose, build }) => {
|
|||
}
|
||||
|
||||
const success = await sendData("POST", "/api/builds", mutationData);
|
||||
setSending(false);
|
||||
if (!success) return;
|
||||
|
||||
if (!loggedInUser) throw Error("unexpected no logged in user");
|
||||
|
|
@ -345,12 +348,7 @@ const BuildModal: React.FC<Props> = ({ onClose, build }) => {
|
|||
</FormControl>
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<Button
|
||||
mr={3}
|
||||
type="submit"
|
||||
// TODO:
|
||||
//isLoading={loading}
|
||||
>
|
||||
<Button mr={3} type="submit" isLoading={sending}>
|
||||
<Trans>Save</Trans>
|
||||
</Button>
|
||||
<Button onClick={onClose} variant="outline">
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import {
|
|||
PROFILE_CHARACTER_LIMIT,
|
||||
} from "lib/validators/profile";
|
||||
import { GetUserByIdentifierData } from "prisma/queries/getUserByIdentifier";
|
||||
import { useState } from "react";
|
||||
import { Controller, useForm } from "react-hook-form";
|
||||
import { FaGamepad, FaTwitch, FaTwitter, FaYoutube } from "react-icons/fa";
|
||||
import { mutate } from "swr";
|
||||
|
|
@ -73,6 +74,7 @@ interface Props {
|
|||
type FormData = z.infer<typeof profileSchemaFrontend>;
|
||||
|
||||
const ProfileModal: React.FC<Props> = ({ onClose, user }) => {
|
||||
const [sending, setSending] = useState(false);
|
||||
const { i18n } = useLingui();
|
||||
|
||||
const { handleSubmit, errors, register, watch, control } = useForm<FormData>({
|
||||
|
|
@ -91,6 +93,7 @@ const ProfileModal: React.FC<Props> = ({ onClose, user }) => {
|
|||
const toast = useToast();
|
||||
|
||||
const onSubmit = async (formData: FormData) => {
|
||||
setSending(true);
|
||||
const mutationData = {
|
||||
...formData,
|
||||
// sens is treated as string on the frontend side of things because
|
||||
|
|
@ -113,6 +116,7 @@ const ProfileModal: React.FC<Props> = ({ onClose, user }) => {
|
|||
}
|
||||
|
||||
const success = await sendData("PUT", "/api/me/profile", mutationData);
|
||||
setSending(false);
|
||||
if (!success) return;
|
||||
|
||||
mutate(`/api/users/${user.id}`);
|
||||
|
|
@ -318,12 +322,7 @@ const ProfileModal: React.FC<Props> = ({ onClose, user }) => {
|
|||
/>
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<Button
|
||||
mr={3}
|
||||
type="submit"
|
||||
// TODO:
|
||||
//isLoading={loading}
|
||||
>
|
||||
<Button mr={3} type="submit" isLoading={sending}>
|
||||
<Trans>Save</Trans>
|
||||
</Button>
|
||||
<Button onClick={onClose} variant="outline">
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user