diff --git a/components/[pageId]/DocumentPage/DocumentPage.tsx b/components/[pageId]/DocumentPage/DocumentPage.tsx index 4d13f84c9d..3bb4bf1858 100644 --- a/components/[pageId]/DocumentPage/DocumentPage.tsx +++ b/components/[pageId]/DocumentPage/DocumentPage.tsx @@ -22,7 +22,7 @@ import { makeSelectSortedViews } from 'components/common/DatabaseEditor/store/vi import { FormFieldAnswers } from 'components/common/form/FormFieldAnswers'; import { FormFieldsEditor } from 'components/common/form/FormFieldsEditor'; import LoadingComponent from 'components/common/LoadingComponent'; -import { useProposalFormAnswers } from 'components/proposals/hooks/useProposalFormAnswers'; +import type { useProposalFormAnswers } from 'components/proposals/hooks/useProposalFormAnswers'; import { ProposalEvaluations } from 'components/proposals/ProposalPage/components/ProposalEvaluations/ProposalEvaluations'; import { ProposalStickyFooter } from 'components/proposals/ProposalPage/components/ProposalStickyFooter/ProposalStickyFooter'; import { RewardEvaluations } from 'components/rewards/components/RewardEvaluations/RewardEvaluations'; @@ -53,7 +53,7 @@ import { ProposalNotesBanner } from './components/ProposalNotesBanner'; import { ProposalProperties } from './components/ProposalProperties'; import { SyncedPageBanner } from './components/SyncedPageBanner'; import type { IPageSidebarContext } from './hooks/usePageSidebar'; -import { useProposal } from './hooks/useProposal'; +import type { useProposal } from './hooks/useProposal'; import { useReward } from './hooks/useReward'; export const defaultPageTop = 56; // we need to add some room for the announcement banner and other banners @@ -72,7 +72,8 @@ export type DocumentPageProps = { setSidebarView?: IPageSidebarContext['setActiveView']; showCard?: (cardId: string | null) => void; showParentChip?: boolean; -}; +} & ReturnType & + ReturnType; function DocumentPageComponent({ insideModal = false, @@ -83,7 +84,23 @@ function DocumentPageComponent({ sidebarView, setSidebarView, showCard, - showParentChip + showParentChip, + proposal, + refreshProposal, + onChangeEvaluation, + onChangeTemplate, + onChangeWorkflow, + onChangeRewardSettings, + onChangeSelectedCredentialTemplates, + refreshProposalFormAnswers, + projectForm, + control, + formFields, + getFieldState, + onSave, + applyProject, + applyProjectMembers, + isLoadingAnswers }: DocumentPageProps) { const { user } = useUser(); const { router } = useCharmRouter(); @@ -99,33 +116,6 @@ function DocumentPageComponent({ const proposalId = page.proposalId; const rewardId = page.bountyId; const { updateURLQuery, navigateToSpacePath } = useCharmRouter(); - - const { - proposal, - refreshProposal, - onChangeEvaluation, - onChangeTemplate, - onChangeWorkflow, - onChangeRewardSettings, - onChangeSelectedCredentialTemplates - } = useProposal({ - proposalId - }); - - const { - control, - formFields, - getFieldState, - applyProject, - applyProjectMembers, - isLoadingAnswers, - projectForm, - onSave, - refreshProposalFormAnswers - } = useProposalFormAnswers({ - proposal - }); - const { onChangeRewardWorkflow, reward, updateReward, refreshReward } = useReward({ rewardId }); @@ -403,6 +393,7 @@ function DocumentPageComponent({ onChangeEvaluation={onChangeEvaluation} onChangeTemplate={onChangeTemplate} refreshProposal={refreshProposal} + refreshProposalFormAnswers={refreshProposalFormAnswers} onChangeWorkflow={onChangeWorkflow} onChangeSelectedCredentialTemplates={onChangeSelectedCredentialTemplates} /> diff --git a/components/[pageId]/DocumentPage/DocumentPageWithSidebars.tsx b/components/[pageId]/DocumentPage/DocumentPageWithSidebars.tsx index abf2255e7c..6e013c5cff 100644 --- a/components/[pageId]/DocumentPage/DocumentPageWithSidebars.tsx +++ b/components/[pageId]/DocumentPage/DocumentPageWithSidebars.tsx @@ -2,6 +2,7 @@ import type { EditorState } from 'prosemirror-state'; import { memo, useEffect, useState } from 'react'; import type { PageSidebarView } from 'components/[pageId]/DocumentPage/hooks/usePageSidebar'; +import { useProposalFormAnswers } from 'components/proposals/hooks/useProposalFormAnswers'; import { useCharmEditor } from 'hooks/useCharmEditor'; import { useCharmRouter } from 'hooks/useCharmRouter'; import { useMdScreen } from 'hooks/useMediaScreens'; @@ -35,6 +36,9 @@ function DocumentPageWithSidebarsComponent(props: DocumentPageWithSidebarsProps) const proposalId = page.proposalId; const rewardId = page.bountyId; + const proposalProps = useProposal({ + proposalId + }); const { proposal, refreshProposal, @@ -43,8 +47,10 @@ function DocumentPageWithSidebarsComponent(props: DocumentPageWithSidebarsProps) onChangeWorkflow, onChangeRewardSettings, onChangeSelectedCredentialTemplates - } = useProposal({ - proposalId + } = proposalProps; + + const proposalAnswersProps = useProposalFormAnswers({ + proposal }); const { onChangeRewardWorkflow, reward, updateReward, refreshReward } = useReward({ @@ -115,6 +121,8 @@ function DocumentPageWithSidebarsComponent(props: DocumentPageWithSidebarsProps) )} {(page.type === 'bounty' || page.type === 'bounty_template') && reward && ( diff --git a/components/common/PageDialog/PageDialog.tsx b/components/common/PageDialog/PageDialog.tsx index 5136846b56..592a0c07a9 100644 --- a/components/common/PageDialog/PageDialog.tsx +++ b/components/common/PageDialog/PageDialog.tsx @@ -4,15 +4,16 @@ import type { Page } from '@charmverse/core/prisma'; import OpenInFullIcon from '@mui/icons-material/OpenInFull'; import { Box } from '@mui/material'; import { usePopupState } from 'material-ui-popup-state/hooks'; -import { useRouter } from 'next/router'; import { useCallback, useEffect, useRef } from 'react'; import charmClient from 'charmClient/charmClient'; import { trackPageView } from 'charmClient/hooks/track'; import { DocumentPage } from 'components/[pageId]/DocumentPage/DocumentPage'; import { DocumentPageProviders } from 'components/[pageId]/DocumentPage/DocumentPageProviders'; +import { useProposal } from 'components/[pageId]/DocumentPage/hooks/useProposal'; import { Button } from 'components/common/Button'; import Dialog from 'components/common/DatabaseEditor/components/dialog'; +import { useProposalFormAnswers } from 'components/proposals/hooks/useProposalFormAnswers'; import { useCharmEditor } from 'hooks/useCharmEditor'; import { useCurrentPage } from 'hooks/useCurrentPage'; import { useCurrentSpace } from 'hooks/useCurrentSpace'; @@ -36,13 +37,21 @@ function PageDialogBase(props: Props) { const mounted = useRef(false); const popupState = usePopupState({ variant: 'popover', popupId: 'page-dialog' }); - const router = useRouter(); const { space } = useCurrentSpace(); const { setCurrentPageId } = useCurrentPage(); const { editMode, resetPageProps, setPageProps } = useCharmEditor(); const { updatePage } = usePages(); const { page } = usePage({ pageIdOrPath: pageId }); + + const proposalProps = useProposal({ + proposalId: page?.proposalId + }); + + const proposalAnswersProps = useProposalFormAnswers({ + proposal: proposalProps.proposal + }); + const pagePermissions = page?.permissionFlags || new AvailablePagePermissions().full; const fullPageUrl = page?.path ? `/${page?.path}` : null; @@ -179,6 +188,8 @@ function PageDialogBase(props: Props) { page={page} savePage={savePage} readOnly={readOnlyPage} + {...proposalProps} + {...proposalAnswersProps} /> )} diff --git a/components/proposals/ProposalPage/components/ProposalEvaluations/ProposalEvaluations.tsx b/components/proposals/ProposalPage/components/ProposalEvaluations/ProposalEvaluations.tsx index 55eec3e0e1..73c40b524a 100644 --- a/components/proposals/ProposalPage/components/ProposalEvaluations/ProposalEvaluations.tsx +++ b/components/proposals/ProposalPage/components/ProposalEvaluations/ProposalEvaluations.tsx @@ -17,6 +17,7 @@ export type ProposalEvaluationsProps = { onChangeRewardSettings?: ProposalSettingsProps['onChangeRewardSettings']; onChangeSelectedCredentialTemplates: ProposalSettingsProps['onChangeSelectedCredentialTemplates']; refreshProposal?: VoidFunction; + refreshProposalFormAnswers?: VoidFunction; pagePath?: string; pageTitle?: string; templateId?: string | null; @@ -38,6 +39,7 @@ export function ProposalEvaluations({ onChangeWorkflow, onChangeRewardSettings, refreshProposal, + refreshProposalFormAnswers, onChangeSelectedCredentialTemplates, pagePath, pageTitle, @@ -78,6 +80,7 @@ export function ProposalEvaluations({ onChangeEvaluation={onChangeEvaluation} readOnlyCredentialTemplates={!isAdmin} onChangeSelectedCredentialTemplates={onChangeSelectedCredentialTemplates} + refreshProposalFormAnswers={refreshProposalFormAnswers} refreshProposal={refreshProposal} refreshPage={refreshPage} onChangeRewardSettings={onChangeRewardSettings} diff --git a/components/proposals/ProposalPage/components/ProposalEvaluations/components/Review/EvaluationsReview.tsx b/components/proposals/ProposalPage/components/ProposalEvaluations/components/Review/EvaluationsReview.tsx index bc176f53a2..c955d4e553 100644 --- a/components/proposals/ProposalPage/components/ProposalEvaluations/components/Review/EvaluationsReview.tsx +++ b/components/proposals/ProposalPage/components/ProposalEvaluations/components/Review/EvaluationsReview.tsx @@ -67,6 +67,7 @@ export type Props = { pageTitle?: string; expanded: boolean; refreshPage?: VoidFunction; + refreshProposalFormAnswers?: VoidFunction; }; export function EvaluationsReview({ @@ -80,6 +81,7 @@ export function EvaluationsReview({ onChangeRewardSettings, readOnlyCredentialTemplates, refreshProposal: _refreshProposal, + refreshProposalFormAnswers, expanded: expandedContainer, templateId, refreshPage @@ -166,6 +168,8 @@ export function EvaluationsReview({ await refreshIssuableCredentials(); await _refreshProposal?.(); await refreshPage?.(); + // update proposal questions as some may appear after certain steps + await refreshProposalFormAnswers?.(); } useEffect(() => { diff --git a/components/proposals/hooks/useProposalFormAnswers.ts b/components/proposals/hooks/useProposalFormAnswers.ts index 36aadf22cb..bfc749857b 100644 --- a/components/proposals/hooks/useProposalFormAnswers.ts +++ b/components/proposals/hooks/useProposalFormAnswers.ts @@ -14,6 +14,10 @@ export function useProposalFormAnswers({ proposal }: { proposal?: ProposalWithUs }); const { trigger } = useUpdateProposalFormFieldAnswers({ proposalId: proposal?.id }); + // form field visibility may change when evaluation steps are completed, so we need to recalculate the form fields + const visibleFormFields = + proposal?.form?.formFields?.filter((formField) => !formField.isHiddenByDependency).length || 0; + // only calculate this once on load, since answers will become stale and override the formFIelds const formFields = useMemo( () => @@ -31,7 +35,7 @@ export function useProposalFormAnswers({ proposal }: { proposal?: ProposalWithUs options: (formField.options ?? []) as SelectOptionType[] }; }), - [!!proposal?.form?.formFields, !!answers, proposal?.id] + [!!proposal?.form?.formFields, visibleFormFields, !!answers, proposal?.id] ); // get Answers form