Skip to content

Commit

Permalink
Merge pull request #2269 from HHS/mb/TTAHUB-3187/improve-recipient-gr…
Browse files Browse the repository at this point in the history
…oups-component

Fix for recipient groups component
  • Loading branch information
thewatermethod authored Jul 12, 2024
2 parents fd063d7 + 0bf407b commit a0d8060
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
10 changes: 7 additions & 3 deletions frontend/src/components/RecipientsWithGroups.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, {
useState,
useEffect,
} from 'react';
import PropTypes from 'prop-types';
import useDeepCompareEffect from 'use-deep-compare-effect';
import {
Dropdown,
Expand All @@ -16,20 +17,19 @@ import GroupAlert from './GroupAlert';

const placeholderText = '- Select -';

const RecipientsWithGroups = () => {
const RecipientsWithGroups = ({ regionId }) => {
const {
control,
register,
watch,
setValue,
} = useFormContext();

// Recipients.
const regionId = watch('regionId');
const watchFormRecipients = watch('recipients');
const watchGroup = watch('recipientGroup');

const [recipientOptions, setRecipientOptions] = useState();

useEffect(() => {
async function fetchRecipients() {
if (!recipientOptions && regionId) {
Expand Down Expand Up @@ -205,4 +205,8 @@ const RecipientsWithGroups = () => {
);
};

RecipientsWithGroups.propTypes = {
regionId: PropTypes.number.isRequired,
};

export default RecipientsWithGroups;
10 changes: 8 additions & 2 deletions frontend/src/pages/SessionForm/pages/participants.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ const Participants = ({ formData }) => {
const isIstVisit = watch('isIstVisit') === 'yes';
const isNotIstVisit = watch('isIstVisit') === 'no';

const regionId = watch('regionId');
const eventRegionId = formData.event ? formData.event.regionId : null;

// handle existing sessions
useDeepCompareEffect(() => {
const {
Expand Down Expand Up @@ -141,7 +144,9 @@ const Participants = ({ formData }) => {

{isNotIstVisit && (
<>
<RecipientsWithGroups />
<RecipientsWithGroups
regionId={regionId || eventRegionId}
/>
<div className="margin-top-2">
<FormItem
label="Recipient participants"
Expand Down Expand Up @@ -184,7 +189,6 @@ const Participants = ({ formData }) => {

{(isIstVisit || isNotIstVisit) && (
<>

<ParticipantsNumberOfParticipants
isHybrid={isHybrid}
register={register}
Expand Down Expand Up @@ -251,13 +255,15 @@ Participants.propTypes = {
recipients: PropTypes.arrayOf(PropTypes.shape({
label: PropTypes.string,
})),
regionId: PropTypes.number,
istSelectionComplete: PropTypes.bool,
event: PropTypes.shape({
id: PropTypes.number,
name: PropTypes.string,
displayId: PropTypes.string,
status: PropTypes.string,
pageState: PropTypes.objectOf(PropTypes.string),
regionId: PropTypes.number,
}),
numberOfParticipants: PropTypes.number,
numberOfParticipantsInPerson: PropTypes.number,
Expand Down

0 comments on commit a0d8060

Please sign in to comment.