Still refactoring...
This commit is contained in:
parent
f4ba7afb69
commit
b375cfbdd7
|
@ -94,31 +94,14 @@ const User: Component<Props> = (props) => {
|
||||||
return errors;
|
return errors;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const credentials = adminCredentials();
|
||||||
|
const { database } = credentials || { database: null };
|
||||||
|
|
||||||
const { form, data, setData, setInitialValues, reset } = createForm({
|
const { form, data, setData, setInitialValues, reset } = createForm({
|
||||||
onSubmit: submitHandler,
|
onSubmit: submitHandler,
|
||||||
extend: reporter(),
|
extend: reporter(),
|
||||||
validate: validationHandler,
|
validate: validationHandler,
|
||||||
initialValues: getValues(),
|
initialValues: getValues() || { database },
|
||||||
});
|
|
||||||
|
|
||||||
createEffect(() => {
|
|
||||||
console.log({ caller: 'user / createEffect', values: getValues() });
|
|
||||||
if (isNew()) {
|
|
||||||
const credentials = adminCredentials();
|
|
||||||
if (!credentials) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const { database } = credentials;
|
|
||||||
setData('database', database);
|
|
||||||
} else {
|
|
||||||
setInitialValues(getValues());
|
|
||||||
reset();
|
|
||||||
console.log({
|
|
||||||
caller: 'user / createEffect',
|
|
||||||
values: getValues(),
|
|
||||||
data: data(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const createUserHandler = async () => {
|
const createUserHandler = async () => {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { useParams } from 'solid-start';
|
import { useParams } from 'solid-start';
|
||||||
import User from '~/components/user';
|
import User from '~/components/user';
|
||||||
import { createEffect, createSignal } from 'solid-js';
|
import { createEffect, createSignal, Show } from 'solid-js';
|
||||||
import { adminCredentials, CheckCredentials } from '~/components/credentials';
|
import { adminCredentials, CheckCredentials } from '~/components/credentials';
|
||||||
import { get } from '~/lib/get';
|
import { get } from '~/lib/get';
|
||||||
|
|
||||||
|
@ -23,7 +23,9 @@ export default () => {
|
||||||
<main>
|
<main>
|
||||||
<h1>User</h1>
|
<h1>User</h1>
|
||||||
<CheckCredentials>
|
<CheckCredentials>
|
||||||
|
<Show when={!!user()}>
|
||||||
<User values={user} />
|
<User values={user} />
|
||||||
|
</Show>
|
||||||
</CheckCredentials>
|
</CheckCredentials>
|
||||||
</main>
|
</main>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue