diff --git a/web-ui/src/components/guild-results/EditGuildModal.jsx b/web-ui/src/components/guild-results/EditGuildModal.jsx index 7eb1860b6d..fc17c433ac 100644 --- a/web-ui/src/components/guild-results/EditGuildModal.jsx +++ b/web-ui/src/components/guild-results/EditGuildModal.jsx @@ -187,6 +187,9 @@ const EditGuildModal = ({ guild = {}, open, onSave, onClose, headerText }) => { ? editedGuild.guildMembers.filter(guildMember => guildMember.lead) : [] } + isOptionEqualToValue={(option, value) => + value && option.id === value.memberId + } onChange={onLeadsChange} getOptionLabel={option => option.name} renderInput={params => ( @@ -211,7 +214,7 @@ const EditGuildModal = ({ guild = {}, open, onSave, onClose, headerText }) => { onChange={onGuildMembersChange} getOptionLabel={option => option.name} isOptionEqualToValue={(option, value) => - value ? value.id === option.id : false + value && option.id === value.memberId } renderInput={params => ( { - const { state } = useContext(AppContext); - const { guilds } = state; + const { dispatch, state } = useContext(AppContext); + const { csrf, guilds, userProfile } = state; + const [addOpen, setAddOpen] = useState(false); + const [openedGuildId, setOpenedGuildId] = useState(''); const [searchText, setSearchText] = useState(''); + useQueryParameters([ + { + name: 'addOpen', + default: false, + value: addOpen, + setter: setAddOpen + }, + { + name: 'guild', + default: '', + value: openedGuildId, + setter: setOpenedGuildId + }, + { + name: 'search', + default: '', + value: searchText, + setter: setSearchText + } + ]); + + const handleOpen = () => setAddOpen(true); + + const handleClose = () => setAddOpen(false); + + const isAdmin = userProfile?.role?.includes('ADMIN'); + return (
@@ -49,7 +82,33 @@ const GuildResults = () => { setSearchText(e.target.value); }} /> - +
+ {isAdmin && ( + <> + + { + if (csrf) { + let res = await createGuild(guild, csrf); + let data = + res.payload && res.payload.data && !res.error + ? res.payload.data + : null; + if (data) { + dispatch({ type: ADD_GUILD, payload: data }); + } + handleClose(); + } + }} + headerText="Add A New Guild" + /> + + )} +
{guilds?.length @@ -59,6 +118,8 @@ const GuildResults = () => { key={`guild-summary-${guild.id}`} index={index} guild={guild} + isOpen={guild.id === openedGuildId} + onGuildSelect={setOpenedGuildId} /> ) : null ) diff --git a/web-ui/src/components/guild-results/GuildSummaryCard.jsx b/web-ui/src/components/guild-results/GuildSummaryCard.jsx index b746b863d9..c784beec42 100644 --- a/web-ui/src/components/guild-results/GuildSummaryCard.jsx +++ b/web-ui/src/components/guild-results/GuildSummaryCard.jsx @@ -57,10 +57,10 @@ const propTypes = { const displayName = 'GuildSummaryCard'; -const GuildSummaryCard = ({ guild, index }) => { +const GuildSummaryCard = ({ guild, index, isOpen, onGuildSelect }) => { const { state, dispatch } = useContext(AppContext); const { guilds, userProfile, csrf } = state; - const [open, setOpen] = useState(false); + const [open, setOpen] = useState(isOpen); const [openDelete, setOpenDelete] = useState(false); const [tooltipIsOpen, setTooltipIsOpen] = useState(false); const isAdmin = @@ -80,8 +80,14 @@ const GuildSummaryCard = ({ guild, index }) => { ? false : leads.some(lead => lead.memberId === userProfile.memberProfile.id); - const handleOpen = () => setOpen(true); - const handleClose = () => setOpen(false); + const handleOpen = () => { + setOpen(true); + onGuildSelect(guild.id); + }; + const handleClose = () => { + setOpen(false); + onGuildSelect(''); + }; const handleOpenDeleteConfirmation = () => setOpenDelete(true); const handleCloseDeleteConfirmation = () => setOpenDelete(false); diff --git a/web-ui/src/components/guild-results/GuildsActions.jsx b/web-ui/src/components/guild-results/GuildsActions.jsx deleted file mode 100644 index 9b85031f99..0000000000 --- a/web-ui/src/components/guild-results/GuildsActions.jsx +++ /dev/null @@ -1,60 +0,0 @@ -import React, { useContext, useState } from 'react'; - -import AddGuildModal from './EditGuildModal'; -import { createGuild } from '../../api/guild'; -import { AppContext } from '../../context/AppContext'; -import { ADD_GUILD } from '../../context/actions'; - -import { Button } from '@mui/material'; -import GroupIcon from '@mui/icons-material/Group'; - -import './GuildResults.css'; - -const displayName = 'GuildsActions'; - -const GuildsActions = () => { - const { state, dispatch } = useContext(AppContext); - const [open, setOpen] = useState(false); - - const { csrf, userProfile } = state; - - const handleOpen = () => setOpen(true); - - const handleClose = () => setOpen(false); - - const isAdmin = userProfile?.role?.includes('ADMIN'); - - return ( -
- {isAdmin && ( - <> - - { - if (csrf) { - let res = await createGuild(guild, csrf); - let data = - res.payload && res.payload.data && !res.error - ? res.payload.data - : null; - if (data) { - dispatch({ type: ADD_GUILD, payload: data }); - } - handleClose(); - } - }} - headerText="Add A New Guild" - /> - - )} -
- ); -}; - -GuildsActions.displayName = displayName; - -export default GuildsActions; diff --git a/web-ui/src/components/guild-results/GuildsActions.test.jsx b/web-ui/src/components/guild-results/GuildsActions.test.jsx deleted file mode 100644 index 844df478e8..0000000000 --- a/web-ui/src/components/guild-results/GuildsActions.test.jsx +++ /dev/null @@ -1,39 +0,0 @@ -import React from 'react'; -import GuildsActions from './GuildsActions'; -import { AppContextProvider } from '../../context/AppContext'; - -const initialState = { - state: { - userProfile: { - name: 'holmes', - memberProfile: { - pdlId: '', - title: 'Tester', - workEmail: 'test@tester.com' - }, - role: ['MEMBER'], - imageUrl: - 'https://upload.wikimedia.org/wikipedia/commons/7/74/SNL_MrBill_Doll.jpg' - }, - guilds: [ - { - id: '3fa85f64-5717-4562-b3fc-2c963f66afa6', - name: 'string', - description: 'string' - }, - { - id: '3fa4-5717-4562-b3fc-2c963f66afa6', - name: 'stuff', - description: '' - } - ] - } -}; - -it('renders correctly', () => { - snapshot( - - - - ); -});