Skip to content

Commit

Permalink
refactor: use antd third party library to enhance the user experience
Browse files Browse the repository at this point in the history
  • Loading branch information
Leon-Chin committed Dec 16, 2023
1 parent 7c8fee6 commit c74c81c
Show file tree
Hide file tree
Showing 25 changed files with 90 additions and 66 deletions.
7 changes: 4 additions & 3 deletions src/components/Cards/AppointmentCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import CancelIcon from "@mui/icons-material/Cancel";
import Backdrop from "@mui/material/Backdrop";
import CircularProgress from "@mui/material/CircularProgress";
import API from "../../api";
import { message } from "antd";

export default function AppointmentCard(props) {
const [openBackdrop, setOpenBackdrop] = useState(false);
Expand All @@ -19,15 +20,15 @@ export default function AppointmentCard(props) {
});
if (res.data.error) {
setOpenBackdrop(false);
alert(res.data.erroMsg);
message.error(res.data.erroMsg);
} else {
setOpenBackdrop(false);
alert(res.data.msg);
message.error(res.data.msg);
window.location.reload();
}
} catch (error) {
setOpenBackdrop(false);
alert(error.response.data.errorMsg);
message.error(error.response.data.errorMsg);
console.log(error);
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/components/Cards/BookingCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { useNavigate, createSearchParams } from "react-router-dom";

import jwt from "jsonwebtoken";
import API from "../../api";
import { message } from "antd";

export default function BookingCard(props) {
const [openBackdrop, setOpenBackdrop] = useState(false);
Expand All @@ -27,7 +28,7 @@ export default function BookingCard(props) {
if (props.linkto === "staff") {
setOpenBackdrop(false);
if (!validateEmail(props.ptemail)) {
alert("Enter a valid email");
message.error("Enter a valid email");
return;
}
}
Expand Down Expand Up @@ -67,7 +68,7 @@ export default function BookingCard(props) {
const res = await API.bookAppointment(postData);
if (res.data.error) {
setOpenBackdrop(false);
alert(res.data.errorMsg);
message.error(res.data.errorMsg);
} else {
setOpenBackdrop(false);
navigate({
Expand All @@ -81,7 +82,7 @@ export default function BookingCard(props) {
}
} catch (error) {
setOpenBackdrop(false);
alert(error.response.data.errorMsg);
message.error(error.response.data.errorMsg);
console.log(error);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Cards/DashCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Typography from "@mui/material/Typography";
import { useNavigate, useLocation, createSearchParams } from "react-router-dom";
import "./DashCard.css";
import { PaymentContext } from "../../pages/PatientDash/Tabs/MakePayment";
import { StaffPaymentContext } from "../Dashboards/StaffDash/Tabs/MakePayment";
import { StaffPaymentContext } from "../../pages/StaffDash/Tabs/MakePayment";

export default function DashCard(props) {
const payment = React.useContext(
Expand Down
5 changes: 3 additions & 2 deletions src/components/Cards/DocListCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import TextField from "@mui/material/TextField";
import Backdrop from "@mui/material/Backdrop";
import CircularProgress from "@mui/material/CircularProgress";
import API from "../../api";
import { message } from "antd";


const styles = {
Expand Down Expand Up @@ -46,15 +47,15 @@ export default function DocListCard(props) {
const res = await API.updateFee({ docName: props.heading, fee: newFee });
if (res.data.error) {
setOpenBackdrop(false);
alert(res.data.errorMsg);
message.error(res.data.errorMsg);
} else {
setOpenBackdrop(false);
setNewFee("");
window.location.reload();
}
} catch (error) {
setOpenBackdrop(false);
alert(error.response.data.errorMsg);
message.error(error.response.data.errorMsg);
console.log(error);
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/components/Cards/DuePaymentCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Backdrop from "@mui/material/Backdrop";
import CircularProgress from "@mui/material/CircularProgress";
import { useNavigate, createSearchParams } from "react-router-dom";
import API from "../../api";
import { message } from "antd";

export default function DuePaymentCard(props) {
const [openBackdrop, setOpenBackdrop] = useState(false);
Expand All @@ -33,15 +34,15 @@ export default function DuePaymentCard(props) {
});
if (res.data.error) {
setOpenBackdrop(false);
alert(res.data.erroMsg);
message.error(res.data.erroMsg);
} else {
setOpenBackdrop(false);
alert(res.data.msg);
message.error(res.data.msg);
window.location.reload();
}
} catch (error) {
setOpenBackdrop(false);
alert(error.response.data.errorMsg);
message.error(error.response.data.errorMsg);
console.log(error);
}
}
Expand Down
13 changes: 7 additions & 6 deletions src/components/Cards/FeedbackCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Tooltip from "@mui/material/Tooltip";
import Backdrop from "@mui/material/Backdrop";
import CircularProgress from "@mui/material/CircularProgress";
import API from "../../api";
import { message } from "antd";

export default function FeedbackCard(props) {
const [openBackdrop, setOpenBackdrop] = useState(false);
Expand All @@ -36,15 +37,15 @@ export default function FeedbackCard(props) {
});
if (res.data.error) {
setOpenBackdrop(false);
alert(res.data.errorMsg);
message.error(res.data.errorMsg);
} else {
setOpenBackdrop(false);
setSubmit(true);
alert(res.data.msg);
message.error(res.data.msg);
}
} catch (error) {
setOpenBackdrop(false);
alert(error.response.data.errorMsg);
message.error(error.response.data.errorMsg);
console.log(error);
}
}
Expand All @@ -61,17 +62,17 @@ export default function FeedbackCard(props) {
});
if (res.data.error) {
setOpenBackdrop(false);
alert(res.data.errorMsg);
message.error(res.data.errorMsg);
} else {
setOpenBackdrop(false);
setFeedbackText("");
setValue(0);
setSubmit(false);
alert(res.data.msg);
message.error(res.data.msg);
}
} catch (error) {
setOpenBackdrop(false);
alert(error.response.data.errorMsg);
message.error(error.response.data.errorMsg);
console.log(error);
}
}
Expand Down
13 changes: 7 additions & 6 deletions src/components/Cards/VerifyCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Backdrop from "@mui/material/Backdrop";
import CircularProgress from "@mui/material/CircularProgress";
import { useNavigate, createSearchParams } from "react-router-dom";
import API from "../../api";
import { message } from "antd";

const styleVerify = {
backgroundColor: "#64dd17",
Expand Down Expand Up @@ -41,7 +42,7 @@ export default function VerifyCard(props) {
const res = await API.verify({ email: props.subheading });
if (res.data.error) {
setOpenBackdrop(false);
alert(res.data.errorMsg);
message.error(res.data.errorMsg);
} else {
setOpenBackdrop(false);
if (props.unvuser === "doctor") {
Expand All @@ -54,14 +55,14 @@ export default function VerifyCard(props) {
})}`,
});
} else {
if (!alert(res.data.msg)) {
if (!message.error(res.data.msg)) {
window.location.reload();
}
}
}
} catch (error) {
setOpenBackdrop(false);
alert(error.response.data.errorMsg);
message.error(error.response.data.errorMsg);
console.log(error);
}
}
Expand All @@ -72,16 +73,16 @@ export default function VerifyCard(props) {
const res = await API.reject({ data: { email: props.subheading } });
if (res.data.error) {
setOpenBackdrop(false);
alert(res.data.errorMsg);
message.error(res.data.errorMsg);
} else {
setOpenBackdrop(false);
if (!alert(res.data.msg)) {
if (!message.error(res.data.msg)) {
window.location.reload();
}
}
} catch (error) {
setOpenBackdrop(false);
alert(error.response.data.errorMsg);
message.error(error.response.data.errorMsg);
console.log(error);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/components/DashBar/DashBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Backdrop from "@mui/material/Backdrop";
import CircularProgress from "@mui/material/CircularProgress";
import { useNavigate } from "react-router-dom";
import API from "../../api";
import { message } from "antd";

export default function DashBar() {
const [openBackdrop, setOpenBackdrop] = useState(false);
Expand All @@ -37,7 +38,7 @@ export default function DashBar() {
} catch (error) {
setOpenBackdrop(false);
console.error(error);
alert(error.response.data.error);
message.error(error.response.data.error);
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/components/FileUploader/FileUploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Typography from "@mui/material/Typography";
import Backdrop from "@mui/material/Backdrop";
import CircularProgress from "@mui/material/CircularProgress";
import API from "../../api";
import { message } from "antd";

const Input = styled("input")({
display: "none",
Expand Down Expand Up @@ -50,18 +51,18 @@ export default function FileUploader(props) {
const res = await API.uploadPrescription(formData);
if (res.data.error) {
setOpenBackdrop(false);
alert(res.data.errorMsg);
message.error(res.data.errorMsg);
} else {
setOpenBackdrop(false);
setFileName(null);
setErrFileName(null);
if (!alert(res.data.msg)) {
if (!message.error(res.data.msg)) {
window.location.reload();
}
}
} catch (error) {
setOpenBackdrop(false);
alert(error.response.data.errorMsg);
message.error(error.response.data.errorMsg);
console.log(error);
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/components/Payments/Card/CardPay.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import "react-credit-cards/es/styles-compiled.css";
import "./CardPay.css";
import API from "../../../api";
import { useSearchParams, useNavigate } from "react-router-dom";
import { message } from "antd";

function CardPay() {
const [openBackdrop, setOpenBackdrop] = useState(false);
Expand Down Expand Up @@ -80,14 +81,14 @@ function CardPay() {
const res = await API.makePayment({ pemail, demail, doa });
if (res.data.error) {
setOpenBackdrop(false);
alert(res.data.errorMsg);
message.error(res.data.errorMsg);
} else {
setOpenBackdrop(false);
alert(res.data.msg);
message.error(res.data.msg);
}
} catch (error) {
setOpenBackdrop(false);
alert(error.response.data.errorMsg);
message.error(error.response.data.errorMsg);
console.error(error);
}
setNumber("");
Expand Down
7 changes: 4 additions & 3 deletions src/components/Payments/Cash/CashPay.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Backdrop from "@mui/material/Backdrop";
import CircularProgress from "@mui/material/CircularProgress";
import { useSearchParams, useNavigate } from "react-router-dom";
import API from "../../../api";
import { message } from "antd";

function CashPay() {
const navigate = useNavigate();
Expand All @@ -25,15 +26,15 @@ function CashPay() {
const res = await API.makePayment({ pemail, demail, doa });
if (res.data.error) {
setOpenBackdrop(false);
alert(res.data.errorMsg);
message.error(res.data.errorMsg);
} else {
setOpenBackdrop(false);
alert(res.data.msg);
message.error(res.data.msg);
setConfirm(true);
}
} catch (error) {
setOpenBackdrop(false);
alert(error.response.data.errorMsg);
message.error(error.response.data.errorMsg);
console.error(error);
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/components/Payments/UPI/UpiPay.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Backdrop from "@mui/material/Backdrop";
import CircularProgress from "@mui/material/CircularProgress";
import { useSearchParams, useNavigate } from "react-router-dom";
import API from "../../../api";
import { message } from "antd";

function UpiPay() {
const navigate = useNavigate();
Expand All @@ -25,15 +26,15 @@ function UpiPay() {
const res = await API.makePayment({ pemail, demail, doa });
if (res.data.error) {
setOpenBackdrop(false);
alert(res.data.errorMsg);
message.error(res.data.errorMsg);
} else {
setOpenBackdrop(false);
alert(res.data.msg);
message.error(res.data.msg);
setConfirm(true);
}
} catch (error) {
setOpenBackdrop(false);
alert(error.response.data.errorMsg);
message.error(error.response.data.errorMsg);
console.error(error);
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/pages/AdminDash/Tabs/DocList.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Link } from "react-router-dom";
import DashBar from "../../../components/DashBar/DashBar";
import DocListCard from "../../../components/Cards/DocListCard";
import API from "../../../api";
import { message } from "antd";

function DocList() {
const [openBackdrop, setOpenBackdrop] = useState(false);
Expand All @@ -21,14 +22,14 @@ function DocList() {
const res = await API.docList();
if (res.data.error) {
setOpenBackdrop(false);
alert(res.data.errorMsg);
message.error(res.data.errorMsg);
} else {
setOpenBackdrop(false);
setDocs(res.data)
}
} catch (error) {
setOpenBackdrop(false);
alert(error.response.data.errorMsg);
message.error(error.response.data.errorMsg);
console.log(error);
}
}
Expand Down
Loading

0 comments on commit c74c81c

Please sign in to comment.