diff --git a/client/src/App.js b/client/src/App.js index 1e9bc95..d28feda 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -248,25 +248,27 @@ const App = (props) => { component={StudentAccountCreation} /> {/* Admin routes from here */} + + - + { const [errors, setErrors] = useState(null); const [noData, setNoData] = useState(null); const [selectedColumn, setSelectedColumn] = useState([]); - const [submitted, setSubmitted ] = useState(false); + const [submitted, setSubmitted] = useState(false); const [transQuery, transResult] = useLazyQuery(GetSuccessFullTransactions, { variables: { session: selectedSession, diff --git a/client/src/components/searchStudentAccount.js b/client/src/components/searchStudentAccount.js index 00280d2..d37bbba 100644 --- a/client/src/components/searchStudentAccount.js +++ b/client/src/components/searchStudentAccount.js @@ -1,6 +1,9 @@ import React, { useState, useEffect } from "react"; import { useLazyQuery, useMutation } from "@apollo/client"; -import { ActivateDeactivateUser } from "../graphql/mutation"; +import { + ActivateDeactivateUser, + ActivateGroupUsers, +} from "../graphql/mutation"; import { SearchUserAccount } from "../graphql/queries"; import styled from "styled-components"; import Loading from "./common/loading"; @@ -20,10 +23,14 @@ const SearchStudentAccount = () => { ActivateDeactivateUser ); + const [activateGroupUser, activateGroupResult] = useMutation( + ActivateGroupUsers + ); + useEffect(() => { if (searchResult.data) { const users = searchResult.data.searchStudentAccount; - + if (users.length > 0) { setUsers(users); setNoData(false); @@ -48,6 +55,17 @@ const SearchStudentAccount = () => { } }, [activateResult.data, activateResult.error]); + useEffect(() => { + if (activateGroupResult.data) { + setSubmitted(!submitted); + window.alert("successful"); + } + if (activateResult.error) { + setSubmitted(!submitted); + setErrors(activateGroupResult.error); + } + }, [activateGroupResult.data, activateGroupResult.error]); + const performSearchInput = (e) => { const value = e.target.value; setRegNumber(value); @@ -83,6 +101,26 @@ const SearchStudentAccount = () => { }); } catch (error) {} }; + + const handleActivate = () => { + setSubmitted(!submitted) + try { + activateGroupUser({ + variables: { + groupReg: regNumber, + }, + refetchQueries: [ + { + query: SearchUserAccount, + variables: { + regNumber: regNumber, + }, + }, + ], + }); + } catch (error) {} + }; + return (
@@ -115,6 +153,22 @@ const SearchStudentAccount = () => {
{noData &&

Your query returned no result!

} + {users.length > 1 && ( +
+ +
+
+
+ )} + {users.length > 0 && ( { + const docsToUpdate = await fastConn.models.User.find({ + regNumber: { $regex: groupReg, $options: "i" }, + }); + docsToUpdate.map(async (doc) => { + doc.active = !doc.active; + await doc.save(); + }); + return true; + } + ), }, LoginUserResult: { __resolveType(obj) { diff --git a/server/src/schema/user.js b/server/src/schema/user.js index 00ceadf..46daa82 100644 --- a/server/src/schema/user.js +++ b/server/src/schema/user.js @@ -22,6 +22,7 @@ export default gql` role: String! ): Boolean activateDeactivateUser(userId: String!): Boolean + activateUserInGroups(groupReg: String!): Boolean } union LoginUserResult = User | Error