@@ -11,12 +11,12 @@ import { Tabs } from "@/components/primitives/tabs";
1111import { PageHint } from "@/components/PageHint" ;
1212import { SIM_AUTH_ENABLED } from "@/lib/featureFlags" ;
1313import { useAuth } from "@/app/auth/AuthContext" ;
14+ import { formatProposalSubmitError } from "@/lib/proposalSubmitErrors" ;
1415import {
1516 apiChambers ,
1617 apiProposalDraftDelete ,
1718 apiProposalDraftSave ,
1819 apiProposalSubmitToPool ,
19- getApiErrorPayload ,
2020} from "@/lib/apiClient" ;
2121import type { ChamberDto } from "@/types/api" ;
2222import { BudgetStep } from "./proposalCreation/steps/BudgetStep" ;
@@ -43,54 +43,6 @@ import {
4343} from "./proposalCreation/types" ;
4444import { getWizardTemplate } from "./proposalCreation/templates/registry" ;
4545
46- const proposalTypeLabel : Record < string , string > = {
47- basic : "Basic" ,
48- fee : "Fee distribution" ,
49- monetary : "Monetary system" ,
50- core : "Core infrastructure" ,
51- administrative : "Administrative" ,
52- "dao-core" : "DAO core" ,
53- } ;
54-
55- const formatProposalType = ( value : string ) : string =>
56- proposalTypeLabel [ value ] ?? value . replace ( / - / g, " " ) ;
57-
58- const formatSubmitError = ( error : unknown ) : string => {
59- const payload = getApiErrorPayload ( error ) ;
60- const details = payload ?. error ?? null ;
61- if ( ! details ) return ( error as Error ) . message ?? "Submit failed." ;
62-
63- const code = typeof details . code === "string" ? details . code : "" ;
64- if ( code === "proposal_type_ineligible" || code === "tier_ineligible" ) {
65- const requiredTier =
66- typeof details . requiredTier === "string"
67- ? details . requiredTier
68- : "a higher tier" ;
69- const proposalType =
70- typeof details . proposalType === "string"
71- ? formatProposalType ( details . proposalType )
72- : "this" ;
73- return `Not eligible for ${ proposalType } proposals. Required tier: ${ requiredTier } .` ;
74- }
75-
76- if ( code === "proposal_submit_ineligible" ) {
77- const chamberId =
78- typeof details . chamberId === "string" ? details . chamberId : "" ;
79- if ( chamberId === "general" ) {
80- return "General chamber proposals require voting rights in any chamber." ;
81- }
82- if ( chamberId ) {
83- return `Only chamber members can submit to ${ formatProposalType ( chamberId ) } .` ;
84- }
85- }
86-
87- if ( code === "draft_not_submittable" ) {
88- return "Draft is incomplete. Fill required fields before submitting." ;
89- }
90-
91- return details . message ?? ( error as Error ) . message ?? "Submit failed." ;
92- } ;
93-
9446const ProposalCreation : React . FC = ( ) => {
9547 const auth = useAuth ( ) ;
9648 const navigate = useNavigate ( ) ;
@@ -435,7 +387,7 @@ const ProposalCreation: React.FC = () => {
435387 clearDraftStorage ( ) ;
436388 navigate ( `/app/proposals/${ res . proposalId } /pp` ) ;
437389 } catch ( error ) {
438- setSubmitError ( formatSubmitError ( error ) ) ;
390+ setSubmitError ( formatProposalSubmitError ( error ) ) ;
439391 } finally {
440392 setSubmitting ( false ) ;
441393 }
0 commit comments