44import * as React from 'react' ;
55import { useRouter } from 'next/navigation' ;
66import { PageSection , Flex , FlexItem , Title , PageBreadcrumb , Breadcrumb , BreadcrumbItem } from '@patternfly/react-core' ;
7- import { EditFormData , KnowledgeFormData , SkillFormData } from '@/types' ;
7+ import { ContributionFormData , EditFormData , KnowledgeFormData , SkillFormData } from '@/types' ;
88import PageDescriptionWithHelp from '@/components/Common/PageDescriptionWithHelp' ;
9+ import { isDraftDataExist } from '@/components/Contribute/Utils/autoSaveUtils' ;
910import {
1011 DraftContributionLabel ,
1112 KnowledgeContributionLabel ,
@@ -15,6 +16,7 @@ import {
1516
1617interface Props {
1718 editFormData ?: EditFormData < SkillFormData | KnowledgeFormData > ;
19+ draftData ?: ContributionFormData ;
1820 isEdit ?: boolean ;
1921 isSkill ?: boolean ;
2022 description : React . ReactNode ;
@@ -25,6 +27,7 @@ interface Props {
2527
2628const ContributePageHeader : React . FC < Props > = ( {
2729 editFormData,
30+ draftData,
2831 isEdit = false ,
2932 isSkill = false ,
3033 description,
@@ -33,9 +36,10 @@ const ContributePageHeader: React.FC<Props> = ({
3336 actions
3437} ) => {
3538 const router = useRouter ( ) ;
39+ const currentData = draftData || editFormData ?. formData ;
3640 const contributionType = isSkill ? 'skill' : 'knowledge' ;
37- const viewUrl = `/contribute/${ isSkill ? 'skill' : 'knowledge' } /${ editFormData ?. formData . branchName } ${ editFormData ?. isDraft ? '/isDraft' : '' } ` ;
38- const contributionTitle = editFormData ?. formData ?. submissionSummary || `Draft ${ contributionType } contribution` ;
41+ const viewUrl = `/contribute/${ isSkill ? 'skill' : 'knowledge' } /${ currentData ?. branchName } ` ;
42+ const contributionTitle = currentData ?. submissionSummary || `Draft ${ contributionType } contribution` ;
3943
4044 return (
4145 < >
@@ -58,9 +62,7 @@ const ContributePageHeader: React.FC<Props> = ({
5862 router . push ( viewUrl ) ;
5963 } }
6064 >
61- { ! editFormData
62- ? `Contribute ${ contributionType } `
63- : editFormData ?. formData ?. submissionSummary || `Draft ${ contributionType } contribution` }
65+ { ! editFormData ? `Contribute ${ contributionType } ` : currentData ?. submissionSummary || `Draft ${ contributionType } contribution` }
6466 </ BreadcrumbItem >
6567 ) : null }
6668 < BreadcrumbItem isActive >
@@ -78,16 +80,16 @@ const ContributePageHeader: React.FC<Props> = ({
7880 < Title headingLevel = "h1" size = "2xl" >
7981 { ! editFormData
8082 ? `Submit ${ contributionType } contribution`
81- : editFormData ?. formData ?. submissionSummary || `Draft ${ isSkill ? 'skill' : 'knowledge' } contribution` }
83+ : currentData ?. submissionSummary || `Draft ${ isSkill ? 'skill' : 'knowledge' } contribution` }
8284 </ Title >
8385 </ FlexItem >
8486 < FlexItem > { isSkill ? < SkillContributionLabel /> : < KnowledgeContributionLabel /> } </ FlexItem >
85- { editFormData ?. isDraft ? (
87+ { currentData && isDraftDataExist ( currentData . branchName ) ? (
8688 < FlexItem >
8789 < DraftContributionLabel />
8890 </ FlexItem >
8991 ) : null }
90- { editFormData && ! editFormData . isSubmitted ? (
92+ { ! editFormData ? (
9193 < FlexItem >
9294 < NewContributionLabel isCompact = { false } />
9395 </ FlexItem >
0 commit comments