Skip to content

Commit b9b584b

Browse files
committed
react-app: Prevent throwing error when proposal type is unknown
refs oursky#362
1 parent d04f706 commit b9b584b

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

react-app/src/components/ProposalDetailScreen/ProposalHeader.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ const ProposalTypeAndProposer: React.FC<{ proposal: Proposal }> = ({
160160
}) => {
161161
const { type, proposerAddress, submitTime } = proposal;
162162

163+
const typeNameId = getProposalTypeMessage(type);
164+
163165
return (
164166
<div
165167
className={cn(
@@ -175,7 +177,7 @@ const ProposalTypeAndProposer: React.FC<{ proposal: Proposal }> = ({
175177
<LocalizedText messageID="ProposalDetail.proposalType" />
176178
</p>
177179
<p className={cn("text-sm", "mb-4")}>
178-
<LocalizedText messageID={getProposalTypeMessage(type)} />
180+
{typeNameId !== null ? <LocalizedText messageID={typeNameId} /> : type}
179181
</p>
180182
<p className={cn("text-sm", "text-app-lightgreen", "mb-1")}>
181183
<LocalizedText messageID="ProposalDetail.publishedBy" />

react-app/src/components/proposals/ProposalCard.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ const ProposalCard: React.FC<ProposalCardProps> = (props) => {
5050
});
5151
}, [proposal]);
5252

53+
const proposalTypeNameId = useMemo(
54+
() => getProposalTypeMessage(proposal.type),
55+
[proposal]
56+
);
57+
5358
return (
5459
<div
5560
className={cn(
@@ -86,7 +91,11 @@ const ProposalCard: React.FC<ProposalCardProps> = (props) => {
8691
"text-app-darkgrey"
8792
)}
8893
>
89-
<LocalizedText messageID={getProposalTypeMessage(proposal.type)} />
94+
{proposalTypeNameId !== null ? (
95+
<LocalizedText messageID={proposalTypeNameId} />
96+
) : (
97+
proposal.type
98+
)}
9099
</span>
91100
<h1
92101
className={cn(

react-app/src/components/proposals/utils.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export function getProposalStatusBadgeConfig(
2727
}
2828
}
2929

30-
export function getProposalTypeMessage(type: ProposalType): MessageID {
30+
export function getProposalTypeMessage(type: string): MessageID | null {
3131
switch (type) {
3232
case ProposalType.Text:
3333
return "ProposalScreen.proposalType.text";
@@ -40,7 +40,7 @@ export function getProposalTypeMessage(type: ProposalType): MessageID {
4040
case ProposalType.CancelSoftwareUpgrade:
4141
return "ProposalScreen.proposalType.cancelSoftwareUpgrade";
4242
default:
43-
throw new Error("Unknown proposal type");
43+
return null;
4444
}
4545
}
4646

0 commit comments

Comments
 (0)