Skip to content

Commit

Permalink
ASAP-497 Manuscript Eligibility (#4330)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabiayako authored Jul 15, 2024
1 parent a077b94 commit ac0b20c
Show file tree
Hide file tree
Showing 27 changed files with 998 additions and 85 deletions.
32 changes: 32 additions & 0 deletions apps/crn-frontend/src/network/teams/EligibilityReasonProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React, { createContext, useState } from 'react';

type EligibilityReasonContextData = {
eligibilityReasons: Set<string>;
setEligibilityReasons: (newEligibilityReason: Set<string>) => void;
};

export const EligibilityReasonContext =
createContext<EligibilityReasonContextData>(
{} as EligibilityReasonContextData,
);

export const EligibilityReasonProvider = ({
children,
}: {
children: React.ReactNode;
}) => {
const [eligibilityReasons, setEligibilityReasons] = useState<Set<string>>(
new Set(),
);

return (
<EligibilityReasonContext.Provider
value={{
eligibilityReasons,
setEligibilityReasons,
}}
>
{children}
</EligibilityReasonContext.Provider>
);
};
3 changes: 3 additions & 0 deletions apps/crn-frontend/src/network/teams/TeamManuscript.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { network } from '@asap-hub/routing';
import { FormProvider, useForm } from 'react-hook-form';
import { useSetRecoilState } from 'recoil';
import { refreshTeamState, usePostManuscript } from './state';
import { useEligibilityReason } from './useEligibilityReason';
import { useManuscriptToast } from './useManuscriptToast';

type TeamManuscriptProps = {
Expand All @@ -16,6 +17,7 @@ type TeamManuscriptProps = {
const TeamManuscript: React.FC<TeamManuscriptProps> = ({ teamId }) => {
const setRefreshTeamState = useSetRecoilState(refreshTeamState(teamId));

const { eligibilityReasons } = useEligibilityReason();
const { setShowSuccessBanner } = useManuscriptToast();
const form = useForm();
const createManuscript = usePostManuscript();
Expand All @@ -37,6 +39,7 @@ const TeamManuscript: React.FC<TeamManuscriptProps> = ({ teamId }) => {
onSuccess={onSuccess}
onSave={createManuscript}
teamId={teamId}
eligibilityReasons={eligibilityReasons}
/>
</Frame>
</FormProvider>
Expand Down
119 changes: 61 additions & 58 deletions apps/crn-frontend/src/network/teams/TeamProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import ProfileSwitch from '../ProfileSwitch';
import { ManuscriptToastProvider } from './ManuscriptToastProvider';
import { useTeamById } from './state';
import TeamManuscript from './TeamManuscript';
import { EligibilityReasonProvider } from './EligibilityReasonProvider';

const loadAbout = () =>
import(/* webpackChunkName: "network-team-about" */ './About');
Expand Down Expand Up @@ -137,67 +138,69 @@ const TeamProfile: FC<TeamProfileProps> = ({ currentTime }) => {
value={{ canShareResearchOutput, canDuplicateResearchOutput }}
>
<ManuscriptToastProvider>
<Switch>
<Route
path={workspace({}).$ + workspace({}).createManuscript.template}
>
<Frame title="Create Manuscript">
<TeamManuscript teamId={teamId} />
</Frame>
</Route>
{canShareResearchOutput && (
<Route path={path + createOutput.template}>
<Frame title="Share Output">
<TeamOutput teamId={teamId} />
<EligibilityReasonProvider>
<Switch>
<Route
path={workspace({}).$ + workspace({}).createManuscript.template}
>
<Frame title="Create Manuscript">
<TeamManuscript teamId={teamId} />
</Frame>
</Route>
)}
{canDuplicateResearchOutput && (
<Route path={path + duplicateOutput.template}>
<Frame title="Duplicate Output">
<DuplicateOutput />
</Frame>
</Route>
)}
<TeamProfilePage
{...team}
teamListElementId={teamListElementId}
upcomingEventsCount={upcomingEvents?.total || 0}
pastEventsCount={pastEvents?.total || 0}
teamOutputsCount={teamOutputsResult.total}
teamDraftOutputsCount={
canShareResearchOutput ? outputDraftResults.total : undefined
}
>
<ProfileSwitch
About={() => (
<About teamListElementId={teamListElementId} team={team} />
)}
currentTime={currentTime}
displayName={team.displayName}
eventConstraint={{ teamId }}
isActive={!team?.inactiveSince}
Outputs={
<Outputs
userAssociationMember={canShareResearchOutput}
team={team}
/>
}
DraftOutputs={
<Outputs
team={team}
draftOutputs
userAssociationMember={canShareResearchOutput}
/>
{canShareResearchOutput && (
<Route path={path + createOutput.template}>
<Frame title="Share Output">
<TeamOutput teamId={teamId} />
</Frame>
</Route>
)}
{canDuplicateResearchOutput && (
<Route path={path + duplicateOutput.template}>
<Frame title="Duplicate Output">
<DuplicateOutput />
</Frame>
</Route>
)}
<TeamProfilePage
{...team}
teamListElementId={teamListElementId}
upcomingEventsCount={upcomingEvents?.total || 0}
pastEventsCount={pastEvents?.total || 0}
teamOutputsCount={teamOutputsResult.total}
teamDraftOutputsCount={
canShareResearchOutput ? outputDraftResults.total : undefined
}
paths={paths}
type="team"
Workspace={() => (
<Workspace team={{ ...team, tools: team.tools ?? [] }} />
)}
/>
</TeamProfilePage>
</Switch>
>
<ProfileSwitch
About={() => (
<About teamListElementId={teamListElementId} team={team} />
)}
currentTime={currentTime}
displayName={team.displayName}
eventConstraint={{ teamId }}
isActive={!team?.inactiveSince}
Outputs={
<Outputs
userAssociationMember={canShareResearchOutput}
team={team}
/>
}
DraftOutputs={
<Outputs
team={team}
draftOutputs
userAssociationMember={canShareResearchOutput}
/>
}
paths={paths}
type="team"
Workspace={() => (
<Workspace team={{ ...team, tools: team.tools ?? [] }} />
)}
/>
</TeamProfilePage>
</Switch>
</EligibilityReasonProvider>
</ManuscriptToastProvider>
</ResearchOutputPermissionsContext.Provider>
);
Expand Down
3 changes: 3 additions & 0 deletions apps/crn-frontend/src/network/teams/Workspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import { network, useRouteParams } from '@asap-hub/routing';
import { ToastContext } from '@asap-hub/react-context';

import { usePatchTeamById } from './state';
import { useEligibilityReason } from './useEligibilityReason';

interface WorkspaceProps {
readonly team: TeamResponse & Required<Pick<TeamResponse, 'tools'>>;
}
const Workspace: React.FC<WorkspaceProps> = ({ team }) => {
const route = network({}).teams({}).team({ teamId: team.id }).workspace({});
const { path } = useRouteMatch();
const { setEligibilityReasons } = useEligibilityReason();

const [deleting, setDeleting] = useState(false);
const patchTeam = usePatchTeamById(team.id);
Expand All @@ -27,6 +29,7 @@ const Workspace: React.FC<WorkspaceProps> = ({ team }) => {
<Route path={path}>
<TeamProfileWorkspace
{...team}
setEligibilityReasons={setEligibilityReasons}
tools={team.tools}
onDeleteTool={
deleting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { Route, Router } from 'react-router-dom';
import { RecoilRoot } from 'recoil';

import { createManuscript } from '../api';
import { EligibilityReasonProvider } from '../EligibilityReasonProvider';
import { ManuscriptToastProvider } from '../ManuscriptToastProvider';
import { refreshTeamState } from '../state';
import TeamManuscript from '../TeamManuscript';
Expand Down Expand Up @@ -60,7 +61,9 @@ const renderPage = async (
<Router history={history}>
<Route path={path}>
<ManuscriptToastProvider>
<TeamManuscript teamId={teamId} />
<EligibilityReasonProvider>
<TeamManuscript teamId={teamId} />
</EligibilityReasonProvider>
</ManuscriptToastProvider>
</Route>
</Router>
Expand Down Expand Up @@ -122,6 +125,7 @@ it('can publish a form when the data is valid and navigates to team workspace',
{
title,
teamId,
eligibilityReasons: [],
versions: [
{
lifecycle: 'Typeset proof',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
import { refreshResearchOutputState } from '../../../shared-research/state';
import { createResearchOutputListAlgoliaResponse } from '../../../__fixtures__/algolia';
import { createResearchOutput, getTeam } from '../api';
import { EligibilityReasonProvider } from '../EligibilityReasonProvider';
import { ManuscriptToastProvider } from '../ManuscriptToastProvider';
import { refreshTeamState } from '../state';
import TeamProfile from '../TeamProfile';
Expand Down Expand Up @@ -98,7 +99,9 @@ const renderPage = async (
}
>
<ManuscriptToastProvider>
<TeamProfile currentTime={currentTime} />
<EligibilityReasonProvider>
<TeamProfile currentTime={currentTime} />
</EligibilityReasonProvider>
</ManuscriptToastProvider>
</Route>
</Router>
Expand Down Expand Up @@ -179,6 +182,14 @@ it('displays manuscript success toast message and user can dismiss toast', async
expect(await screen.findByText(/tools/i)).toBeVisible();

userEvent.click(screen.getByText(/Share Manuscript/i));
userEvent.click(screen.getByText(/Yes/i));

userEvent.click(
screen.getByText(
'The manuscript resulted from a pivot that was made as part of the team’s ASAP-funded proposal.',
),
);
userEvent.click(screen.getByText(/Continue/i));

const submitButton = screen.getByRole('button', { name: /Submit/i });

Expand Down
1 change: 1 addition & 0 deletions apps/crn-frontend/src/network/teams/__tests__/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ describe('Manuscript', () => {
const payload: ManuscriptPostRequest = {
title: 'The Manuscript',
teamId: '42',
eligibilityReasons: [],
versions: [
{
lifecycle: 'Publication',
Expand Down
5 changes: 5 additions & 0 deletions apps/crn-frontend/src/network/teams/useEligibilityReason.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { useContext } from 'react';

import { EligibilityReasonContext } from './EligibilityReasonProvider';

export const useEligibilityReason = () => useContext(EligibilityReasonContext);
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ describe('Manuscripts Contentful Data Provider', () => {
},
],
},
eligibilityReasons: {
'en-US': [],
},
versions: {
'en-US': [
{
Expand Down
10 changes: 8 additions & 2 deletions apps/crn-server/test/fixtures/manuscript.fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,17 @@ export const getManuscriptPostBody = (): ManuscriptPostRequest => {
const { title, teamId, versions } = getManuscriptDataObject();

const { createdBy: _, publishedAt: __, ...version } = versions[0]!;
return { title, teamId, versions: [version] };
return { title, teamId, eligibilityReasons: [], versions: [version] };
};

export const getManuscriptCreateDataObject = (): ManuscriptCreateDataObject => {
const { title, teamId, versions } = getManuscriptDataObject();

return { title, teamId, versions, userId: 'user-id-0' };
return {
title,
teamId,
eligibilityReasons: [],
versions,
userId: 'user-id-0',
};
};
1 change: 1 addition & 0 deletions apps/storybook/src/TeamProfileWorkspace.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default {
export const Normal = () => (
<TeamProfileWorkspace
{...createTeamResponse()}
setEligibilityReasons={() => {}}
tools={[
{
name: 'My Tool',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module.exports.description = 'Create eligibility field';

module.exports.up = (migration) => {
const manuscripts = migration.editContentType('manuscripts');

manuscripts
.createField('eligibilityReasons')
.name('Eligibility Reasons')
.type('Array')
.localized(false)
.required(false)
.validations([])
.disabled(false)
.omitted(false)
.items({
type: 'Symbol',
validations: [
{
in: ['projects', 'method-or-resource', 'pivot', 'leadership'],
},
],
});
manuscripts.changeFieldControl(
'eligibilityReasons',
'builtin',
'checkbox',
{},
);
};

module.exports.down = (migration) => {
const manuscripts = migration.editContentType('manuscripts');
manuscripts.deleteField('eligibilityReasons');
};
Loading

0 comments on commit ac0b20c

Please sign in to comment.