Source: pages-sections/Manage-Suggestions-Sections/WaterSugCard.js

import React, { useState, useEffect } from "react";
import { useRouter } from "next/router";
import classNames from "classnames";
import { makeStyles } from "@material-ui/core/styles";
import InputAdornment from "@material-ui/core/InputAdornment";
import People from "@material-ui/icons/People";
import Icon from "@material-ui/core/Icon";
import Button from "/components/CustomButtons/Button.js";
import Card from "/components/Card/Card.js";
import CardBody from "/components/Card/CardBody.js";
import CardFooter from "/components/Card/CardFooter.js";
import CustomInput from "/components/CustomInput/CustomInput.js";
import { useAuth } from "../../context/AuthContext";
import styles from "/styles/jss/nextjs-material-kit/pages/profilePage.js";
import { getDatabase, ref, onValue, set } from "firebase/database";
import { fetchPoints } from "../../data/retrievesuggestedpoi.js";
import GridContainer from "/components/Grid/GridContainer.js";
import Grid from "@material-ui/core/Grid";
import { rejectPOI } from "../../data/rejectpoi.js";
import { acceptPOI } from "../../data/acceptpoi.js";
import {
  AccountCircle,
  LocationOn,
  FitnessCenter,
  Height,
  SettingsApplications,
  Person,
  Wc,
} from "@material-ui/icons";

const useStyles = makeStyles(styles);
const useStyly = makeStyles({
  card: {
    marginTop: "10px",
  },
  cardBody: {
    marginTop: "10px",
  },
  inputIconsColor: {
    color: "#9c27b0",
  },
  button: {
    "&:hover": {
      backgroundColor: "primary",
    },
  },
  formContainer: {
    display: "flex",
    flexDirection: "column",
    alignItems: "center",
    marginTop: "15px",
  },
  container: {
    display: "flex",
    justifyContent: "space-between",
    alignItems: "center",
  },
  data: {
    textAlign: "center",
    flex: "1",
  },
  cardFooterEdit: {
    display: "flex",
    justifyContent: "space-between",
  },
  cardFooterInfo: {
    display: "flex",
    justifyContent: "flex-end",
  },
});

/**
 * The function `handleReject` asynchronously rejects a point of interest (POI) with the type
 * "waterpoint" and logs a message before reloading the router, handling any errors that occur.
 */
export const handleReject = async () => {
  try {
    await rejectPOI("waterpoint", data.id);
    console.log("POI rejected");
    router.push("/mainmenu");
  } catch (error) {
    console.error("Error rejecting POI:", error);
  }
};

/**
 * The `handleApprove` function asynchronously accepts a point of interest (POI) named "waterpoint",
 * logs a message if the POI is approved, and reloads the router, handling any errors that may occur.
 */
export const handleApprove = async () => {
  try {
    await acceptPOI("waterpoint", data);
    console.log("POI approved");
    router.push("/mainmenu");
  } catch (error) {
    console.error("Error approving POI:", error);
  }
};

/**
 * The `WaterSugCard` function is a React component that displays information about a water point of
 * interest (POI) and provides buttons to reject or approve the POI.
 * @param props - The `WaterSugCard` component is a functional component that receives props as input.
 * @returns The `WaterSugCard` component is being returned. It renders a card displaying information
 * about a point of interest (POI) related to water, with options to reject or approve the POI. The
 * card includes details such as Name, Latitude, Longitude, and Description of the POI. The component
 * also contains buttons for rejecting and approving the POI, which trigger the `handleReject`
 */
export function WaterSugCard(props) {
  const data = props.data;
  console.log(data);
  useEffect(() => {
    console.log(data);
  }, [data]);

  const classes = useStyles();
  const classess = useStyly();
  const router = useRouter();

  return (
    <CardBody>
      <div className={classess.container}>
        <div className={classess.data}>
          <Grid
            container
            rowSpacing={1}
            columnSpacing={{ xs: 1, sm: 2, md: 3 }}
          >
            <Grid item xs={8} sm={12} md={6}>
              <p
                style={{
                  display: "flex",
                  alignItems: "center",
                  fontSize: "18px",
                  paddingTop: "10px",
                }}
              >
                <span style={{ marginRight: "10px", fontWeight: "bold" }}>
                  Name:
                </span>
                {data.Name}
              </p>
              <p
                style={{
                  display: "flex",
                  alignItems: "center",
                  fontSize: "18px",
                }}
              >
                <span style={{ marginRight: "10px", fontWeight: "bold" }}>
                  Latitude:
                </span>
                {data.Y}
              </p>
              <p
                style={{
                  display: "flex",
                  alignItems: "center",
                  fontSize: "18px",
                }}
              >
                <span style={{ marginRight: "10px", fontWeight: "bold" }}>
                  Longitude:
                </span>
                {data.X}
              </p>
              <p
                style={{
                  display: "flex",
                  alignItems: "center",
                  fontSize: "18px",
                }}
              >
                <span style={{ marginRight: "10px", fontWeight: "bold" }}>
                  Description:
                </span>
                {data.description}
              </p>
            </Grid>
            <Grid
              item
              xs={4}
              sm={12}
              md={6}
              container
              justify="flex-end"
              alignItems="flex-end"
            >
              {/* Buttons */}
              <Grid item>
                <Button
                  color="danger"
                  size="sm"
                  style={{ marginLeft: "50px" }}
                  onClick={() => {
                    handleReject();
                  }}
                >
                  Reject
                </Button>
              </Grid>
              <Grid item style={{ marginLeft: "8px" }}>
                {/* Small gap between buttons */}
              </Grid>
              <Grid item>
                <Button
                  color="success"
                  size="sm"
                  onClick={() => {
                    handleApprove();
                  }}
                >
                  Approve
                </Button>
              </Grid>
            </Grid>
          </Grid>
        </div>
      </div>
      <CardFooter className={classess.cardFooterInfo}></CardFooter>
    </CardBody>
  );
}