diff --git a/libs/gql-schema/schema.ts b/libs/gql-schema/schema.ts index 6fe978efc..9287eb738 100644 --- a/libs/gql-schema/schema.ts +++ b/libs/gql-schema/schema.ts @@ -259,7 +259,7 @@ const rootSchema = ` people(organizationId:String, cursor:OffsetLimitCursor, campaignsFilter:CampaignsFilter, role: String, userIds:[String]): UsersReturn peopleByUserIds(userIds:[String], organizationId:String!): UsersList fetchCampaignOverlaps(input: FetchCampaignOverlapInput!): [FetchCampaignOverlapResult]! - assignmentRequests(organizationId: String!, status: String): [AssignmentRequest] + assignmentRequests(organizationId: String!, status: String, excludeStatus: String, limit: Int): [AssignmentRequest] trollAlarms(organizationId: String!, limit: Int!, offset: Int!, token: String, dismissed: Boolean!): TrollAlarmPage! trollAlarmsCount(organizationId: String!, dismissed: Boolean!): TrollAlarmCount!, trollTokens(organizationId: String!): [TrollTrigger] diff --git a/src/containers/AdminAssignmentRequest/components/AssignmentRequestTable.tsx b/src/containers/AdminAssignmentRequest/components/AssignmentRequestTable.tsx index c05adf591..b3c88dbfc 100644 --- a/src/containers/AdminAssignmentRequest/components/AssignmentRequestTable.tsx +++ b/src/containers/AdminAssignmentRequest/components/AssignmentRequestTable.tsx @@ -40,10 +40,6 @@ const rowStyleForStatus = (rowStatus: string) => { let overrideStyle = {}; if (rowStatus === RowWorkStatus.Error) { overrideStyle = { backgroundColor: theme.colors.lightGray }; - } else if (rowStatus === RowWorkStatus.Approved) { - overrideStyle = { opacity: 0, backgroundColor: theme.colors.green }; - } else if (rowStatus === RowWorkStatus.Denied) { - overrideStyle = { opacity: 0, backgroundColor: theme.colors.lightRed }; } return { ...baseStyle, ...overrideStyle }; }; @@ -141,11 +137,20 @@ const AssignmentRequestTable: React.FC = ( {status === RowWorkStatus.Working && ( )} + {status === RowWorkStatus.Approved && "Approved"} + {status === RowWorkStatus.Denied && "Rejected"} ); })} + {assignmentRequests.length === 0 && ( + + + No requests + + + )} diff --git a/src/containers/AdminAssignmentRequest/index.jsx b/src/containers/AdminAssignmentRequest/index.jsx index b4b878dcd..877b2eed5 100644 --- a/src/containers/AdminAssignmentRequest/index.jsx +++ b/src/containers/AdminAssignmentRequest/index.jsx @@ -6,6 +6,7 @@ import DialogContent from "@material-ui/core/DialogContent"; import DialogContentText from "@material-ui/core/DialogContentText"; import DialogTitle from "@material-ui/core/DialogTitle"; import FormControlLabel from "@material-ui/core/FormControlLabel"; +import { withStyles } from "@material-ui/core/styles"; import Switch from "@material-ui/core/Switch"; import isEqual from "lodash/isEqual"; import PropTypes from "prop-types"; @@ -13,15 +14,23 @@ import React, { Component } from "react"; import { RequestAutoApproveType } from "../../api/organization-membership"; import { hasRole } from "../../lib/permissions"; -import { sleep } from "../../lib/utils"; import { loadData } from "../hoc/with-operations"; import AssignmentRequestTable, { RowWorkStatus } from "./components/AssignmentRequestTable"; +const styles = { + pastRequestsSummary: { + cursor: "pointer", + padding: "16px 0", + width: "fit-content" + } +}; + class AdminAssignmentRequest extends Component { state = { assignmentRequests: [], + pastAssignmentRequests: null, autoApproveReqId: undefined }; @@ -63,14 +72,6 @@ class AdminAssignmentRequest extends Component { this.setState({ assignmentRequests }); }; - deleteRequest = (requestId) => { - let { assignmentRequests } = this.state; - assignmentRequests = assignmentRequests.filter( - (request) => request.id !== requestId - ); - this.setState({ assignmentRequests }); - }; - handleDismissAutoApproveRequest = () => this.setState({ autoApproveReqId: undefined }); @@ -86,6 +87,21 @@ class AdminAssignmentRequest extends Component { handleResolveRequest = (approved) => (requestId) => this.resolveRequest(requestId, approved); + handleLoadPastRequests = async ({ target: { open } }) => { + if (!open) return; + const { data } = await this.props.client.query({ + // eslint-disable-next-line @typescript-eslint/no-use-before-define + query: queries.pendingAssignmentRequests.query, + variables: { + organizationId: this.props.match.params.organizationId, + excludeStatus: RowWorkStatus.Inactive, + limit: 100 + }, + fetchPolicy: "network-only" + }); + this.setState({ pastAssignmentRequests: data.assignmentRequests }); + }; + handleNotificationSubscription = ({ target: { checked } }) => { const { node @@ -109,8 +125,6 @@ class AdminAssignmentRequest extends Component { ? RowWorkStatus.Approved : RowWorkStatus.Denied; this.setRequestStatus(requestId, newStatus); - await sleep(2000); - this.deleteRequest(requestId); } catch (exc) { this.setRequestStatus(requestId, RowWorkStatus.Error); } @@ -118,7 +132,11 @@ class AdminAssignmentRequest extends Component { render() { const { currentUser } = this.props.pendingAssignmentRequests; - const { assignmentRequests, autoApproveReqId } = this.state; + const { + assignmentRequests, + pastAssignmentRequests, + autoApproveReqId + } = this.state; const isAdmin = hasRole("ADMIN", currentUser.roles); const membership = currentUser.memberships.edges[0].node; const autoApproveRequest = @@ -159,6 +177,17 @@ class AdminAssignmentRequest extends Component { onApproveRequest={this.handleResolveRequest(true)} onDenyRequest={this.handleResolveRequest(false)} /> +
+ + Past requests + + {pastAssignmentRequests && ( + + )} +
{ + assignmentRequests: async ( + _root, + { organizationId, status, excludeStatus, limit }, + { user } + ) => { await accessRequired(user, organizationId, "SUPERVOLUNTEER"); const query = r @@ -222,6 +226,12 @@ const rootResolvers = { if (status) { query.where({ status }); } + if (excludeStatus) { + query.whereNot({ status: excludeStatus }); + } + if (limit) { + query.orderBy("created_at", "desc").limit(limit); + } const assignmentRequests = await query; const result = assignmentRequests.map((ar) => {