Skip to content

Commit

Permalink
remove log
Browse files Browse the repository at this point in the history
  • Loading branch information
mattcasey committed Dec 20, 2024
1 parent fc2705b commit bba244a
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 36 deletions.
53 changes: 22 additions & 31 deletions components/[pageId]/DocumentPage/DocumentPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand All @@ -72,7 +72,8 @@ export type DocumentPageProps = {
setSidebarView?: IPageSidebarContext['setActiveView'];
showCard?: (cardId: string | null) => void;
showParentChip?: boolean;
};
} & ReturnType<typeof useProposal> &
ReturnType<typeof useProposalFormAnswers>;

function DocumentPageComponent({
insideModal = false,
Expand All @@ -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();
Expand All @@ -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
});
Expand Down Expand Up @@ -403,6 +393,7 @@ function DocumentPageComponent({
onChangeEvaluation={onChangeEvaluation}
onChangeTemplate={onChangeTemplate}
refreshProposal={refreshProposal}
refreshProposalFormAnswers={refreshProposalFormAnswers}
onChangeWorkflow={onChangeWorkflow}
onChangeSelectedCredentialTemplates={onChangeSelectedCredentialTemplates}
/>
Expand Down
13 changes: 11 additions & 2 deletions components/[pageId]/DocumentPage/DocumentPageWithSidebars.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -35,6 +36,9 @@ function DocumentPageWithSidebarsComponent(props: DocumentPageWithSidebarsProps)
const proposalId = page.proposalId;
const rewardId = page.bountyId;

const proposalProps = useProposal({
proposalId
});
const {
proposal,
refreshProposal,
Expand All @@ -43,8 +47,10 @@ function DocumentPageWithSidebarsComponent(props: DocumentPageWithSidebarsProps)
onChangeWorkflow,
onChangeRewardSettings,
onChangeSelectedCredentialTemplates
} = useProposal({
proposalId
} = proposalProps;

const proposalAnswersProps = useProposalFormAnswers({
proposal
});

const { onChangeRewardWorkflow, reward, updateReward, refreshReward } = useReward({
Expand Down Expand Up @@ -115,6 +121,8 @@ function DocumentPageWithSidebarsComponent(props: DocumentPageWithSidebarsProps)
<DocumentColumn>
<DocumentPage
{...props}
{...proposalAnswersProps}
{...proposalProps}
setEditorState={setEditorState}
setSidebarView={setActiveView}
sidebarView={internalSidebarView}
Expand Down Expand Up @@ -160,6 +168,7 @@ function DocumentPageWithSidebarsComponent(props: DocumentPageWithSidebarsProps)
onChangeWorkflow={onChangeWorkflow}
onChangeRewardSettings={onChangeRewardSettings}
onChangeSelectedCredentialTemplates={onChangeSelectedCredentialTemplates}
refreshProposalFormAnswers={proposalAnswersProps.refreshProposalFormAnswers}
/>
)}
{(page.type === 'bounty' || page.type === 'bounty_template') && reward && (
Expand Down
15 changes: 13 additions & 2 deletions components/common/PageDialog/PageDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;

Expand Down Expand Up @@ -179,6 +188,8 @@ function PageDialogBase(props: Props) {
page={page}
savePage={savePage}
readOnly={readOnlyPage}
{...proposalProps}
{...proposalAnswersProps}
/>
)}
</Dialog>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export type ProposalEvaluationsProps = {
onChangeRewardSettings?: ProposalSettingsProps['onChangeRewardSettings'];
onChangeSelectedCredentialTemplates: ProposalSettingsProps['onChangeSelectedCredentialTemplates'];
refreshProposal?: VoidFunction;
refreshProposalFormAnswers?: VoidFunction;
pagePath?: string;
pageTitle?: string;
templateId?: string | null;
Expand All @@ -38,6 +39,7 @@ export function ProposalEvaluations({
onChangeWorkflow,
onChangeRewardSettings,
refreshProposal,
refreshProposalFormAnswers,
onChangeSelectedCredentialTemplates,
pagePath,
pageTitle,
Expand Down Expand Up @@ -78,6 +80,7 @@ export function ProposalEvaluations({
onChangeEvaluation={onChangeEvaluation}
readOnlyCredentialTemplates={!isAdmin}
onChangeSelectedCredentialTemplates={onChangeSelectedCredentialTemplates}
refreshProposalFormAnswers={refreshProposalFormAnswers}
refreshProposal={refreshProposal}
refreshPage={refreshPage}
onChangeRewardSettings={onChangeRewardSettings}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export type Props = {
pageTitle?: string;
expanded: boolean;
refreshPage?: VoidFunction;
refreshProposalFormAnswers?: VoidFunction;
};

export function EvaluationsReview({
Expand All @@ -80,6 +81,7 @@ export function EvaluationsReview({
onChangeRewardSettings,
readOnlyCredentialTemplates,
refreshProposal: _refreshProposal,
refreshProposalFormAnswers,
expanded: expandedContainer,
templateId,
refreshPage
Expand Down Expand Up @@ -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(() => {
Expand Down
6 changes: 5 additions & 1 deletion components/proposals/hooks/useProposalFormAnswers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
() =>
Expand All @@ -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
Expand Down

0 comments on commit bba244a

Please sign in to comment.