1 | import React, { useEffect } from "react";
|
---|
2 | import { useState } from "react";
|
---|
3 | import Navigation from "../Components/Layout/Navbar/Navigation";
|
---|
4 | import { Row, Col, Container, Button, Modal } from "react-bootstrap";
|
---|
5 | import { IoBusinessSharp } from "react-icons/io5";
|
---|
6 | import RegisterBusinessForm from "../Components/Forms/RegisterBusinessForm";
|
---|
7 | import useGet from "../Components/Hooks/useGet";
|
---|
8 | import {Navigate, useNavigate} from "react-router-dom";
|
---|
9 | import {useAuth} from "../Components/Context/AuthContext";
|
---|
10 |
|
---|
11 | const NoBusinessRegisteredError = (props) => {
|
---|
12 | const [show, setShow] = useState(false);
|
---|
13 | const [changed, setChanged] = useState(0);
|
---|
14 | const Auth = useAuth();
|
---|
15 | const isLoggedIn = Auth.userIsAuthenticated();
|
---|
16 | const userId = localStorage.getItem("userId")
|
---|
17 | const [registered, setRegistered] = useState(false);
|
---|
18 | let checked = false;
|
---|
19 | const navigator = useNavigate()
|
---|
20 |
|
---|
21 | const handleClose = () => setShow(false);
|
---|
22 | const handleShow = (e) => {
|
---|
23 | e.preventDefault();
|
---|
24 | setShow(true);
|
---|
25 | };
|
---|
26 |
|
---|
27 | const { data: firma, isLoading: firmaIsLoading, getData: getFirmi} = useGet("/business/" + userId + "/unapproved", changed)
|
---|
28 |
|
---|
29 |
|
---|
30 | useEffect(() => {
|
---|
31 |
|
---|
32 | console.log(firma)
|
---|
33 | setRegistered(() => {
|
---|
34 | return firma !== null && firma.length > 0
|
---|
35 | })
|
---|
36 |
|
---|
37 | }, [firmaIsLoading])
|
---|
38 |
|
---|
39 | // useEffect(() => {
|
---|
40 |
|
---|
41 | // setRegistered(() => {
|
---|
42 | // console.log(data)
|
---|
43 | // return data !== null && data
|
---|
44 | // })
|
---|
45 |
|
---|
46 | // }, [isLoading])
|
---|
47 |
|
---|
48 |
|
---|
49 | if(!isLoggedIn)
|
---|
50 | {
|
---|
51 | return <Navigate to={'/login'}/>
|
---|
52 | }
|
---|
53 |
|
---|
54 | !firmaIsLoading && firma && firma.length > 0 && firma[0].approved && navigator("/resources/hotel")
|
---|
55 |
|
---|
56 |
|
---|
57 | return (
|
---|
58 | <>
|
---|
59 | <Navigation></Navigation>
|
---|
60 | {!registered && (
|
---|
61 | <Container>
|
---|
62 | <Row className="mt-5 mb-3">
|
---|
63 | <Col>
|
---|
64 | <h3 style={{ color: "#159895" }}>
|
---|
65 | За да менаџирате со Вашите ресурси мора да имате регистрирано
|
---|
66 | фирма одобрена од администраторот!
|
---|
67 | </h3>
|
---|
68 | </Col>
|
---|
69 | </Row>
|
---|
70 | <Row>
|
---|
71 | <Col>
|
---|
72 | <Button
|
---|
73 | type="button"
|
---|
74 | onClick={handleShow}
|
---|
75 | style={{
|
---|
76 | backgroundColor: "#159895",
|
---|
77 | border: "2px solid white",
|
---|
78 | }}
|
---|
79 | size="lg"
|
---|
80 | >
|
---|
81 | <span className="ikona my-1" color="white">
|
---|
82 | <IoBusinessSharp style={{ color: "white" }} />
|
---|
83 | </span>
|
---|
84 | <span className="ikona mx-3">Регистрирај фирма</span>
|
---|
85 | </Button>
|
---|
86 | </Col>
|
---|
87 | </Row>
|
---|
88 | </Container>
|
---|
89 | )}
|
---|
90 | {registered && (
|
---|
91 | <>
|
---|
92 | <Container>
|
---|
93 | <Row className="mt-5">
|
---|
94 | <Col className="mb-5">
|
---|
95 | <h3 className="mb-5" style={{ color: "#159895" }}>
|
---|
96 | {" "}
|
---|
97 | За да менаџирате со Вашите ресурси мора да имате регистрирано
|
---|
98 | фирма одобрена од администраторот!
|
---|
99 | </h3>
|
---|
100 | <h4 style={{ color: "#159895" }}>
|
---|
101 | Тековни неодобрени регистрации
|
---|
102 | </h4>
|
---|
103 | </Col>
|
---|
104 | </Row>
|
---|
105 | <Row>
|
---|
106 | <Container className="w-75">
|
---|
107 | <table className="table table-hover">
|
---|
108 | <thead>
|
---|
109 | <tr>
|
---|
110 | <th scope="col">Ред. бр.</th>
|
---|
111 | <th scope="col">Име на фирма</th>
|
---|
112 | <th scope="col">Адреса</th>
|
---|
113 | <th scope="col">Даночен број</th>
|
---|
114 | <th scope="col">Одговорно лице</th>
|
---|
115 | </tr>
|
---|
116 | </thead>
|
---|
117 | <tbody>
|
---|
118 | {!firmaIsLoading && firma.map((f, i) => { return <tr key={f.businessId}>
|
---|
119 | <th scope="row">{i + 1}</th>
|
---|
120 | <td>{f.name}</td>
|
---|
121 | <td>{f.address}</td>
|
---|
122 | <td>{f.edbs}</td>
|
---|
123 | <td>{f.user.name + " " + f.user.surname}</td>
|
---|
124 | </tr>})}
|
---|
125 | </tbody>
|
---|
126 | </table>
|
---|
127 | </Container>
|
---|
128 | </Row>
|
---|
129 | </Container>
|
---|
130 | </>
|
---|
131 | )}
|
---|
132 |
|
---|
133 | <Modal show={show} onHide={handleClose}>
|
---|
134 | <Modal.Header closeButton>
|
---|
135 | <Modal.Title style={{ color: "#159895" }}>
|
---|
136 | Регистрација на фирма
|
---|
137 | </Modal.Title>
|
---|
138 | </Modal.Header>
|
---|
139 | <Modal.Body>
|
---|
140 | <RegisterBusinessForm hide={handleClose} edit={setChanged}></RegisterBusinessForm>
|
---|
141 | </Modal.Body>
|
---|
142 | </Modal>
|
---|
143 | </>
|
---|
144 | );
|
---|
145 | };
|
---|
146 |
|
---|
147 | export default NoBusinessRegisteredError;
|
---|