Skip to content

Commit

Permalink
fix env var
Browse files Browse the repository at this point in the history
  • Loading branch information
mattvagni committed Oct 17, 2023
1 parent ea748be commit 451263c
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions src/contactForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,29 +68,23 @@ export function componentsForDemoRequest(
];
}

function requiredEnvVar(key: string): string {
const envVar = process.env[key];

if (!envVar) {
throw new Error(`Environment variable "${key}" not set.`);
}

return envVar;
function isString(s: unknown): s is string {
return typeof s === 'string';
}

function getLabelTypeIds(formType: FormType): string[] {
if (formType === null) {
return [];
}

const formTypeIdsMap: Record<NonNullable<FormType>, string[]> = {
bug: [requiredEnvVar('NEXT_PUBLIC_PLAIN_LABEL_TYPE_ID_BUG')],
demo: [requiredEnvVar('NEXT_PUBLIC_PLAIN_LABEL_TYPE_ID_DEMO')],
feature: [requiredEnvVar('NEXT_PUBLIC_PLAIN_LABEL_TYPE_ID_FEATURE')],
question: [requiredEnvVar('NEXT_PUBLIC_PLAIN_LABEL_TYPE_ID_QUESTION')],
security: [requiredEnvVar('NEXT_PUBLIC_PLAIN_LABEL_TYPE_ID_SECURITY')],
const formTypeIdsMap: Record<NonNullable<FormType>, Array<string | undefined>> = {
bug: [process.env.NEXT_PUBLIC_PLAIN_LABEL_TYPE_ID_BUG],
demo: [process.env.NEXT_PUBLIC_PLAIN_LABEL_TYPE_ID_DEMO],
feature: [process.env.NEXT_PUBLIC_PLAIN_LABEL_TYPE_ID_FEATURE],
question: [process.env.NEXT_PUBLIC_PLAIN_LABEL_TYPE_ID_QUESTION],
security: [process.env.NEXT_PUBLIC_PLAIN_LABEL_TYPE_ID_SECURITY],
};
return formTypeIdsMap[formType];
return formTypeIdsMap[formType].filter(isString);
}

function getPriority(formType: FormType, bugIsBlocking: boolean): 0 | 1 | 2 | 3 {
Expand Down

1 comment on commit 451263c

@vercel
Copy link

@vercel vercel bot commented on 451263c Oct 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.