Skip to content

Commit

Permalink
routes back to list
Browse files Browse the repository at this point in the history
  • Loading branch information
Amogh-Bharadwaj committed Sep 29, 2023
1 parent b6eacb8 commit 8806a93
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 3 additions & 0 deletions ui/app/peers/create/configuration/handlers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AppRouterInstance } from 'next/dist/shared/lib/app-router-context';
import { Dispatch, SetStateAction } from 'react';
import { checkFormFields } from './schema';
import { PeerConfig } from './types';
Expand Down Expand Up @@ -58,6 +59,7 @@ export const handleCreate = async (
config: PeerConfig,
setMessage: Dispatch<SetStateAction<{ ok: boolean; msg: string }>>,
setLoading: Dispatch<SetStateAction<boolean>>,
router: AppRouterInstance,
name?: string
) => {
let isValid = validateFields(type, config, setMessage, name);
Expand All @@ -78,6 +80,7 @@ export const handleCreate = async (
return;
} else {
setMessage({ ok: true, msg: 'Peer created successfully' });
router.push('/peers');
}
setLoading(false);
};
13 changes: 10 additions & 3 deletions ui/app/peers/create/configuration/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import { LayoutMain, RowWithTextField } from '@/lib/Layout';
import { Panel } from '@/lib/Panel';
import { TextField } from '@/lib/TextField';
import Link from 'next/link';
import { useSearchParams } from 'next/navigation';
import { useRouter, useSearchParams } from 'next/navigation';
import { useState } from 'react';
import PgConfig from './configForm';
import { handleCreate, handleValidate } from './handlers';
import { postgresSetting } from './helpers/pg';
import { PeerConfig } from './types';

export default function CreateConfig() {
const searchParams = useSearchParams();
const router = useRouter();
const dbType = searchParams.get('dbtype') || '';
const [name, setName] = useState<string>('');
const [config, setConfig] = useState<PeerConfig>({
Expand Down Expand Up @@ -76,7 +76,14 @@ export default function CreateConfig() {
<Button
variant='normalSolid'
onClick={() =>
handleCreate(dbType, config, setFormMessage, setLoading, name)
handleCreate(
dbType,
config,
setFormMessage,
setLoading,
router,
name
)
}
>
Create
Expand Down

0 comments on commit 8806a93

Please sign in to comment.