Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: show only active, ongoing calls in the call selector on the proposal clone window #675

Merged
merged 9 commits into from
Aug 1, 2024
9 changes: 5 additions & 4 deletions apps/backend/src/mutations/ProposalMutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,10 +565,11 @@ export default class ProposalMutations {
if (
await this.callDataSource.isCallEnded(callId, checkIfInternalCallActive)
) {
return rejection(
'Can not clone proposal because the call is not active',
{ callId, agent, sourceProposal }
);
return rejection('Cannot clone the proposal because the call has ended', {
callId,
agent,
sourceProposal,
});
}

const call = await this.callDataSource.getCall(callId);
Expand Down
14 changes: 14 additions & 0 deletions apps/e2e/cypress/e2e/proposals.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,15 @@ context('Proposal tests', () => {
...newCall,
proposalWorkflowId: createdWorkflowId,
});

// Create an ended call to test if it is not available for cloning.
cy.createCall({
...newCall,
shortCode: 'CALL_HAS_ENDED',
endCall: newCall.startCall,
proposalWorkflowId: createdWorkflowId,
});

cy.submitProposal({ proposalPk: createdProposalPk });

cy.login('user1', initialDBData.roles.user);
Expand All @@ -556,6 +565,11 @@ context('Proposal tests', () => {
cy.get('[aria-label="Clone proposal"]').first().click();

cy.get('[data-cy="call-selection"]').click();

cy.get('[data-cy="call-selection-options"]')
.contains('CALL_HAS_ENDED')
.should('not.exist');

cy.get('[data-cy="call-selection-options"]')
.contains(newCall.shortCode)
.click();
Expand Down
44 changes: 26 additions & 18 deletions apps/frontend/src/components/call/CallStatusFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import FormControl from '@mui/material/FormControl';
import InputLabel from '@mui/material/InputLabel';
import MenuItem from '@mui/material/MenuItem';
import Select from '@mui/material/Select';
import React from 'react';
import React, { useContext } from 'react';
import { StringParam, withDefault, QueryParamConfig } from 'use-query-params';

import { UserContext } from 'context/UserContextProvider';

export enum CallStatus {
ALL = 'all',
ACTIVE = 'active',
Expand All @@ -28,22 +30,28 @@ type CallStatusFilterProps = {
onChange: (callStatus: CallStatus) => void;
};

const CallStatusFilter = ({ callStatus, onChange }: CallStatusFilterProps) => (
<FormControl fullWidth>
<InputLabel id="call-status-select-label">Status</InputLabel>
<Select
id="call-status-select"
labelId="call-status-select-label"
onChange={(e) => onChange(e.target.value as CallStatus)}
value={callStatus}
data-cy="call-status-filter"
>
<MenuItem value={CallStatus.ALL}>All</MenuItem>
<MenuItem value={CallStatus.ACTIVE}>Active</MenuItem>
<MenuItem value={CallStatus.ACTIVEINTERNAL}>Active Internal</MenuItem>
<MenuItem value={CallStatus.INACTIVE}>Inactive</MenuItem>
</Select>
</FormControl>
);
const CallStatusFilter = ({ callStatus, onChange }: CallStatusFilterProps) => {
const { isInternalUser } = useContext(UserContext);

return (
<FormControl fullWidth>
<InputLabel id="call-status-select-label">Status</InputLabel>
<Select
id="call-status-select"
labelId="call-status-select-label"
onChange={(e) => onChange(e.target.value as CallStatus)}
value={callStatus}
data-cy="call-status-filter"
>
<MenuItem value={CallStatus.ALL}>All</MenuItem>
<MenuItem value={CallStatus.ACTIVE}>Active</MenuItem>
{isInternalUser ? (
<MenuItem value={CallStatus.ACTIVEINTERNAL}>Active Internal</MenuItem>
) : null}
<MenuItem value={CallStatus.INACTIVE}>Inactive</MenuItem>
</Select>
</FormControl>
);
};

export default CallStatusFilter;
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const CallSelectModalOnProposalsClone = ({
}: CallSelectModalOnProposalsCloneProps) => {
const { calls, loadingCalls } = useCallsData({
isActive: true,
isActiveInternal: true,
isEnded: false,
templateIds: templateId ? [templateId] : undefined,
});

Expand Down
Loading