All files / pages AdminViewPlayPage.jsx

100% Statements 111/111
100% Branches 11/11
100% Functions 2/2
100% Lines 111/111

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 1431x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x 21x   21x   21x 21x 21x 21x 21x 21x 21x 21x 21x   21x   21x 21x 21x 21x 21x 21x 21x 21x 21x 21x   21x   21x 21x 21x 21x 21x 21x 21x 21x 21x 21x   21x   21x 3x 3x   21x 21x 21x 21x 21x 21x 21x 21x 21x 21x   21x 21x 21x 21x 21x 21x   21x 21x 21x 21x 21x   21x 21x 21x 21x 21x   21x 21x 21x 21x 21x 21x   21x 21x 21x 21x 21x 21x       21x 21x 21x 21x 21x 21x     21x 21x 21x 21x 21x 21x   21x 21x         21x 21x 21x 21x 21x 21x   21x         21x   1x  
import React, { useState } from "react";
import BasicLayout from "main/layouts/BasicLayout/BasicLayout";
import { useParams } from "react-router-dom";
import { Card, Container, CardGroup, Button } from "react-bootstrap";
import CommonsOverview from "main/components/Commons/CommonsOverview";
import CommonsPlay from "main/components/Commons/CommonsPlay";
import FarmStats from "main/components/Commons/FarmStats";
import ManageCows from "main/components/Commons/ManageCows";
import Profits from "main/components/Commons/Profits";
import { useBackend } from "main/utils/useBackend";
import { useCurrentUser } from "main/utils/currentUser";
import ChatPanel from "main/components/Chat/ChatPanel";
 
const AdminViewPlayPage = () => {
  const { userId, commonsId } = useParams();
 
  const { data: currentUser } = useCurrentUser();
 
  // Stryker disable all
  const { data: userCommons } = useBackend("/api/usercommons", {
    method: "GET",
    url: "/api/usercommons",
    params: {
      userId: userId,
      commonsId: commonsId,
    },
  });
 
  // Stryker restore all
 
  // Stryker disable all
  const { data: commonsPlus } = useBackend(
    [`/api/commons/plus?id=${commonsId}`],
    {
      method: "GET",
      url: "/api/commons/plus",
      params: {
        id: commonsId,
      },
    },
  );
  // Stryker restore all
 
  // Stryker disable all
  const { data: userCommonsProfits } = useBackend([`/api/profits/all`], {
    method: "GET",
    url: "/api/profits/all",
    params: {
      userId: userId,
      commonsId: commonsId,
    },
  });
  // Stryker restore all
 
  const [isChatOpen, setIsChatOpen] = useState(false);
 
  const toggleChatWindow = () => {
    setIsChatOpen((prevState) => !prevState);
  };
 
  const chatButtonStyle = {
    width: "40px",
    height: "40px",
    borderRadius: "50%",
    backgroundColor: "lightblue",
    color: "black",
    position: "fixed",
    bottom: "20px",
    right: "20px",
  };
 
  const chatContainerStyle = {
    width: "550px",
    position: "fixed",
    bottom: "100px",
    right: "20px",
  };
 
  const bannerStyle = {
    background: "#f0f0f0",
    padding: "10px",
    textAlign: "center",
  };
 
  const visiting_user = userCommons?.username;
  const visiting_commons = commonsPlus?.commons.name;
  // Stryker disable all
  const admin_name = currentUser?.root ? currentUser?.root?.user?.fullName : "";
  // Stryker restore all
 
  return (
    <div>
      <BasicLayout>
        <Card
          style={bannerStyle}
          data-testid="adminviewplaypage-read-only-banner"
        >
          <Card.Body>
            <Card.Title>
              This is a Admin Feature for <strong>{admin_name}</strong>
              <br />
              Visiting Farmer <strong>{visiting_user}</strong>'s Play Page for
              common <strong>{visiting_commons}</strong> in Read Only Mode.
            </Card.Title>
          </Card.Body>
        </Card>
        <Container>
          {!!currentUser && <CommonsPlay currentUser={userCommons} />}
          {!!commonsPlus && (
            <CommonsOverview
              commonsPlus={commonsPlus}
              currentUser={currentUser}
            />
          )}
          <br />
          {!!userCommons && !!commonsPlus && (
            <CardGroup data-testid="adminviewplaypage-card-group">
              <ManageCows
                userCommons={userCommons}
                commons={commonsPlus.commons}
              />
              <FarmStats userCommons={userCommons} />
              <Profits userCommons={userCommons} profits={userCommonsProfits} />
            </CardGroup>
          )}
        </Container>
      </BasicLayout>
      <div style={chatContainerStyle} data-testid="adminviewplaypage-chat-div">
        {!!isChatOpen && <ChatPanel commonsId={userId} />}
        <Button
          style={chatButtonStyle}
          onClick={toggleChatWindow}
          data-testid="adminviewplaypage-chat-toggle"
        >
          {!!isChatOpen ? "▼" : "▲"}
        </Button>
      </div>
    </div>
  );
};
 
export default AdminViewPlayPage;