Skip to content

Commit

Permalink
save button on settings; pass thru status
Browse files Browse the repository at this point in the history
  • Loading branch information
mmkal committed May 9, 2024
1 parent 20b50e6 commit cf81bef
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
4 changes: 2 additions & 2 deletions packages/admin/e2e/setup.seed.ts
Expand Up @@ -11,7 +11,7 @@ test('seed', async ({page, execute}) => {
await page.getByRole('button', {name: 'Add to headers'}).click()
await page.getByLabel('headers.connection-string').fill(adminConnectionString)
await page.getByLabel('apiUrl').fill(apiUrl)
await page.reload()
await page.getByRole('button', {name: 'Save'}).click()

await page.getByRole('button', {name: 'Open sql'}).click()

Expand All @@ -21,7 +21,7 @@ test('seed', async ({page, execute}) => {

await page.getByRole('button', {name: 'Open settings'}).click()
await page.getByLabel('headers.connection-string').fill(connectionString)
await page.reload()
await page.getByRole('button', {name: 'Save'}).click()

await page.getByRole('button', {name: 'Open sql'}).click()
await execute(`
Expand Down
11 changes: 10 additions & 1 deletion packages/admin/src/client/settings.tsx
Expand Up @@ -34,7 +34,16 @@ export const SettingsPanel = () => {
return (
<div className="h-full overflow-auto">
<h1>Settings</h1>
<ZForm useFormProps={{defaultValues: value}} className="gap-5" schema={Settings} onTouch={update} />
<ZForm
useFormProps={{defaultValues: value, mode: 'onSubmit'}}
className="gap-5"
schema={Settings}
submitButton="Save"
onSubmit={values => {
update(values)
window.location.reload()
}}
/>
</div>
)
}
10 changes: 7 additions & 3 deletions packages/admin/src/client/utils/zform/form.tsx
Expand Up @@ -115,10 +115,14 @@ export function ZForm<Z extends z.ZodObject<any>>({useFormProps, ...props}: ZFor
{reflected.map(entry => (
<RenderEntry form={form} entry={entry} key={jKey(entry.path)} />
))}
{props.submitButton || props.onSubmit ? <Button type="submit">Submit</Button> : null}
{typeof props.submitButton === 'string' ? (
<Button type="submit">{props.submitButton}</Button>
) : props.submitButton || props.onSubmit ? (
props.submitButton || <Button type="submit">Submit</Button>
) : null}
</form>
</Form>
{Object.keys(form.formState.errors).length > 0 && (
{/* {Object.keys(form.formState.errors).length > 0 && (
<pre>
{JSON.stringify(
{
Expand All @@ -130,7 +134,7 @@ export function ZForm<Z extends z.ZodObject<any>>({useFormProps, ...props}: ZFor
2,
)}
</pre>
)}
)} */}
</>
)
}
Expand Down
4 changes: 2 additions & 2 deletions packages/admin/src/server/migrations.ts
Expand Up @@ -29,8 +29,8 @@ const getMigratorStuff = async (ctx: ServerContext) => {
}
}

const formatMigrations = (migrations: {name: string; path?: string}[]) =>
migrations.map(m => ({name: m.name, path: m.path}))
const formatMigrations = <Status extends string>(migrations: {name: string; path?: string; status?: Status}[]) =>
migrations.map(m => ({name: m.name, path: m.path, status: m.status}))

export const migrationsRotuer = trpc.router({
up: publicProcedure
Expand Down

0 comments on commit cf81bef

Please sign in to comment.