Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #4

Merged
merged 3 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
feat: add loader when create and update review
  • Loading branch information
ullltimate committed Sep 13, 2023
commit fd6f42820928b4145322a992ffcd72a95b97b47e
32 changes: 26 additions & 6 deletions client/src/components/CreateReview.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Modal, Form, Button, Col, Row } from "react-bootstrap"
import { Modal, Form, Button, Col, Row, Spinner } from "react-bootstrap"
import Select from "./Select"
import { useEffect, useState } from "react";
import { useParams } from "react-router-dom";
Expand Down Expand Up @@ -26,6 +26,7 @@ function CreateReview(props: any){
const CLOUDINARY_CLOUD_NAME: string = import.meta.env.VITE_CLOUDINARY_CLOUD_NAME;
const [urlImage, setUrlImage] = useState('');
const [file, setFile] = useState<any|null>(null);
const [loader, setLoader] = useState(false);

useEffect(() => {
(props.update != '') ? getReview(props.update, setReview) : setReview(null);
Expand All @@ -49,20 +50,24 @@ function CreateReview(props: any){

async function save(){
if(checkInputs([nameReview, title, group, description]) && file){
setLoader(true);
setWarning(false);
if (params.idUser) await createReview(nameReview, title, group, Number(score), tags.split('#').slice(1), description, params.idUser, urlImage);
resetInputs([setNameReview, setTitle, setGroup, setTags, setDescription, setUrlImage]);
setFile(null);
setScore(0);
setWarning(false);
setLoader(false);
} else {
setWarning(true);
}
}

async function update() {
if(checkInputs([nameReview, title, group, description])){
await updateReview(props.update, nameReview, title, group, Number(score), tags.split('#').slice(1), description, urlImage);
setLoader(true);
setWarning(false);
await updateReview(props.update, nameReview, title, group, Number(score), tags.split('#').slice(1), description, urlImage);
setLoader(false);
} else {
setWarning(true);
}
Expand Down Expand Up @@ -158,9 +163,24 @@ function CreateReview(props: any){
<Button variant="secondary" onClick={props.onHide}>
{t('createReview.btnClose')}
</Button>
<Button variant="primary" onClick={() => (props.update === '') ? save() : update()}>
{t('createReview.btnSave')}
</Button>
{
loader
?
<Button variant="primary" disabled>
<Spinner
as="span"
animation="border"
size="sm"
role="status"
aria-hidden="true"
/>
Loading...
</Button>
:
<Button variant="primary" onClick={() => (props.update === '') ? save() : update()}>
{t('createReview.btnSave')}
</Button>
}
</Modal.Footer>
</Modal>
</>
Expand Down
4 changes: 2 additions & 2 deletions client/src/healpers/healper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//export const urlAPI: string = 'https://reviewer-server-dkmy.onrender.com';
export const urlAPI: string = 'https://localhost:7000';
export const urlAPI: string = 'https://reviewer-server-dkmy.onrender.com';
//export const urlAPI: string = 'https://localhost:7000';

export function changeColor(): string{
const colors: string[] = ['primary', 'secondary', 'success', 'danger', 'warning', 'info', 'dark'];
Expand Down