Skip to content

Commit

Permalink
ui(frontend): prevent crashing settings page if versions mismatched b…
Browse files Browse the repository at this point in the history
…etween frontend and backend
  • Loading branch information
634750802 committed Jul 30, 2024
1 parent 939fcca commit 5d704f8
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion frontend/app/src/components/settings/SettingsField.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { type SettingItem, updateSiteSetting } from '@/api/site-settings';
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert';
import { Button } from '@/components/ui/button';
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form';
import { Input } from '@/components/ui/input';
import { Switch } from '@/components/ui/switch';
import { getErrorMessage } from '@/lib/errors';
import { zodResolver } from '@hookform/resolvers/zod';
import { deepEqual } from 'fast-equals';
import { Loader2Icon } from 'lucide-react';
import { Loader2Icon, TriangleAlertIcon } from 'lucide-react';
import { useRouter } from 'next/navigation';
import { cloneElement, type ReactElement, type ReactNode, useCallback, useMemo } from 'react';
import { type ControllerRenderProps, useForm, useFormState, useWatch } from 'react-hook-form';
Expand All @@ -24,6 +25,16 @@ export interface SettingsFieldProps {
export function SettingsField ({ name, item, arrayItemSchema, objectSchema, children }: SettingsFieldProps) {
const router = useRouter();

if (!item) {
return (
<Alert variant="warning">
<TriangleAlertIcon />
<AlertTitle>Failed to load <em>{name}</em></AlertTitle>
<AlertDescription>Frontend and backend services may be misconfigured, please check your deployments.</AlertDescription>
</Alert>
);
}

if (item.data_type === 'list') {
if (!arrayItemSchema) {
throw new Error(`list item requires array item schema`);
Expand Down

0 comments on commit 5d704f8

Please sign in to comment.