Skip to content

Commit

Permalink
feat: add spinner
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksandr Panteleev committed Apr 10, 2023
1 parent 4abeac8 commit fd42072
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/components/ProductForm/ProductForm.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
padding: 10px;
font-size: 1.2rem;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
}

.button:hover {
Expand Down
6 changes: 5 additions & 1 deletion src/components/ProductForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import Header from '../Header';
import CommentField from '../inputs/CommentField';
import FieldWithPreviousValue from '../inputs/FieldWithPreviousValue';
import TextField from '../inputs/TextField';
import Spinner from '../Spinner';

import styles from './ProductForm.module.css';

const ProductForm: React.FC = () => {
const { qrCodeId = null } = useParams<{ qrCodeId: string }>();
const [qrCode, setQrCode] = useState<string>('');
const [isLoading, setIsLoading] = useState<boolean>(false);
const { initialValues, loadData } = useFetchFormData(qrCodeId, setQrCode);
const { handleSubmit } = useSubmitData(setQrCode);

Expand All @@ -24,8 +26,10 @@ const ProductForm: React.FC = () => {
const [isResponsibleDisabled, setIsResponsibleDisabled] = useState(isQrLoaded);

const onSubmit = async (values: ProductData) => {
setIsLoading(true);
await handleSubmit(values);
if (isQrLoaded) await loadData();
setIsLoading(false);
};

useEffect(() => {
Expand Down Expand Up @@ -87,7 +91,7 @@ const ProductForm: React.FC = () => {
previousValue={initialValues?.previousValues?.responsible}
/>
<button className={styles.button} type="submit" disabled={isSubmitDisabled}>
Сохранить
{isLoading ? <Spinner /> : 'Сохранить'}
</button>
</form>
);
Expand Down
14 changes: 14 additions & 0 deletions src/components/Spinner/Spinner.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.spinner {
border: 4px solid rgba(0, 0, 0, 0.1);
border-left-color: #007bff;
border-radius: 50%;
width: 30px;
height: 30px;
animation: spin 1s linear infinite;
}

@keyframes spin {
to {
transform: rotate(360deg);
}
}
9 changes: 9 additions & 0 deletions src/components/Spinner/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';

import styles from './Spinner.module.css';

const Spinner: React.FC = () => {
return <div className={styles.spinner}></div>;
};

export default Spinner;

0 comments on commit fd42072

Please sign in to comment.