dbCheck action
This commit is contained in:
parent
f966422439
commit
0434b9c626
|
@ -10,6 +10,7 @@
|
|||
"@felte/solid": "^1.2.7",
|
||||
"@kobalte/core": "^0.6.1",
|
||||
"@types/pouchdb": "^6.4.0",
|
||||
"lodash": "^4.17.21",
|
||||
"pouchdb": "^8.0.1",
|
||||
"pouchdb-server": "^4.2.0",
|
||||
"uuid": "^9.0.0"
|
||||
|
@ -19,8 +20,9 @@
|
|||
"@solidjs/router": "^0.7.0",
|
||||
"@solidjs/testing-library": "^0.6.1",
|
||||
"@testing-library/jest-dom": "^5.16.5",
|
||||
"@types/lodash": "^4.14.191",
|
||||
"@types/testing-library__jest-dom": "^5.14.5",
|
||||
"@types/uuid": "^9.0.0",
|
||||
"@types/uuid": "^9.0.1",
|
||||
"@vitest/coverage-c8": "^0.28.5",
|
||||
"@vitest/ui": "^0.28.5",
|
||||
"jsdom": "^21.1.0",
|
||||
|
@ -2987,6 +2989,12 @@
|
|||
"integrity": "sha512-xWGDIW6x921xtzPkhiULtthJHoJvBbF3q26fzloPCK0hsvxtPVelvftw3zjbHWSkR2km9Z+4uxbDDK/6Zw9B8w==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/lodash": {
|
||||
"version": "4.14.191",
|
||||
"resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.191.tgz",
|
||||
"integrity": "sha512-BdZ5BCCvho3EIXw6wUCXHe7rS53AIDPLE+JzwgT+OsJk53oBfbSmZZ7CX4VaRoN78N+TJpFi9QPlfIVNmJYWxQ==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/ms": {
|
||||
"version": "0.7.31",
|
||||
"resolved": "https://registry.npmjs.org/@types/ms/-/ms-0.7.31.tgz",
|
||||
|
@ -3186,9 +3194,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@types/uuid": {
|
||||
"version": "9.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-9.0.0.tgz",
|
||||
"integrity": "sha512-kr90f+ERiQtKWMz5rP32ltJ/BtULDI5RVO0uavn1HQUOwjx0R1h0rnDYNL0CepF1zL5bSY6FISAfd9tOdDhU5Q==",
|
||||
"version": "9.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-9.0.1.tgz",
|
||||
"integrity": "sha512-rFT3ak0/2trgvp4yYZo5iKFEPsET7vKydKF+VRCxlQ9bpheehyAJH89dAkaLEq/j/RZXJIqcgsmPJKUP1Z28HA==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/yargs": {
|
||||
|
@ -7258,8 +7266,7 @@
|
|||
"node_modules/lodash": {
|
||||
"version": "4.17.21",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
|
||||
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==",
|
||||
"dev": true
|
||||
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
|
||||
},
|
||||
"node_modules/lodash.debounce": {
|
||||
"version": "4.0.8",
|
||||
|
|
|
@ -15,8 +15,9 @@
|
|||
"@solidjs/router": "^0.7.0",
|
||||
"@solidjs/testing-library": "^0.6.1",
|
||||
"@testing-library/jest-dom": "^5.16.5",
|
||||
"@types/lodash": "^4.14.191",
|
||||
"@types/testing-library__jest-dom": "^5.14.5",
|
||||
"@types/uuid": "^9.0.0",
|
||||
"@types/uuid": "^9.0.1",
|
||||
"@vitest/coverage-c8": "^0.28.5",
|
||||
"@vitest/ui": "^0.28.5",
|
||||
"jsdom": "^21.1.0",
|
||||
|
@ -33,6 +34,7 @@
|
|||
"@felte/solid": "^1.2.7",
|
||||
"@kobalte/core": "^0.6.1",
|
||||
"@types/pouchdb": "^6.4.0",
|
||||
"lodash": "^4.17.21",
|
||||
"pouchdb": "^8.0.1",
|
||||
"pouchdb-server": "^4.2.0",
|
||||
"uuid": "^9.0.0"
|
||||
|
|
|
@ -8,6 +8,8 @@ import PouchDb from 'pouchdb';
|
|||
import { v4 as uuid } from 'uuid';
|
||||
import { put } from '~/lib/db';
|
||||
import { useNavigate } from 'solid-start';
|
||||
import { toHex } from '~/lib/to-hex';
|
||||
import { cloneDeep } from 'lodash';
|
||||
|
||||
interface Props {
|
||||
values?: any;
|
||||
|
@ -39,6 +41,29 @@ const Invitation: Component<Props> = (props) => {
|
|||
return id;
|
||||
});
|
||||
|
||||
const [dbChecking, dbCheck] = createServerAction$(async (args: any) => {
|
||||
console.log({
|
||||
caller: 'Invitation / dbCheck',
|
||||
args,
|
||||
});
|
||||
let baseDbInfo;
|
||||
try {
|
||||
const baseDb = new PouchDb(cloneDeep(args));
|
||||
baseDbInfo = await baseDb.info();
|
||||
} catch (error) {
|
||||
baseDbInfo = error;
|
||||
}
|
||||
const name = `${args.name}/userdb-${toHex(args.auth.username)}`;
|
||||
let userDbInfo;
|
||||
try {
|
||||
const userDb = new PouchDb({ ...args, name });
|
||||
userDbInfo = await userDb.info();
|
||||
} catch (error) {
|
||||
userDbInfo = error;
|
||||
}
|
||||
return { baseDbInfo, userDbInfo, args, name };
|
||||
});
|
||||
|
||||
const submitHandler = async (values: any, context: any) => {
|
||||
console.log({
|
||||
caller: 'Invitation / submitHandler',
|
||||
|
@ -65,11 +90,24 @@ const Invitation: Component<Props> = (props) => {
|
|||
navigate(`/invitations/`);
|
||||
};
|
||||
|
||||
const { form } = createForm({
|
||||
const { form, data } = createForm({
|
||||
onSubmit: submitHandler,
|
||||
initialValues: props?.values,
|
||||
});
|
||||
|
||||
const dbCheckHandler = async () => {
|
||||
const result = await dbCheck({
|
||||
name: data('database'),
|
||||
auth: { username: data('username'), password: data('password') },
|
||||
});
|
||||
console.log({
|
||||
caller: 'Invitation / dbCheckHandler',
|
||||
props,
|
||||
data: data(),
|
||||
result,
|
||||
});
|
||||
};
|
||||
|
||||
console.log({
|
||||
caller: 'Invitation ',
|
||||
props,
|
||||
|
@ -127,13 +165,13 @@ const Invitation: Component<Props> = (props) => {
|
|||
<Match when={!!props.values}>
|
||||
<Button.Root type='submit'>Save</Button.Root>
|
||||
<Button.Root onclick={deleteHandler}>Delete</Button.Root>
|
||||
<Button.Root onclick={cancelHandler}>Cancel</Button.Root>
|
||||
</Match>
|
||||
<Match when={!props.values}>
|
||||
<Button.Root type='submit'>Create</Button.Root>
|
||||
<Button.Root onclick={cancelHandler}>Cancel</Button.Root>
|
||||
</Match>
|
||||
</Switch>
|
||||
<Button.Root onclick={dbCheckHandler}>DB check</Button.Root>
|
||||
<Button.Root onclick={cancelHandler}>Cancel</Button.Root>
|
||||
</form>
|
||||
);
|
||||
};
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
// see https://9to5answer.com/javascript-unicode-string-to-hex
|
||||
|
||||
export const toHex = (str: string) => {
|
||||
let hex;
|
||||
try {
|
||||
hex = unescape(encodeURIComponent(str))
|
||||
.split('')
|
||||
.map(function (v) {
|
||||
return v.charCodeAt(0).toString(16);
|
||||
})
|
||||
.join('');
|
||||
} catch (e) {
|
||||
hex = str;
|
||||
console.log('invalid text input: ' + str);
|
||||
}
|
||||
return hex;
|
||||
};
|
||||
|
|
@ -27,7 +27,7 @@ export default () => {
|
|||
|
||||
return (
|
||||
<main>
|
||||
<h1>Invitation: </h1>
|
||||
<h1>Invitation</h1>
|
||||
<Show when={!invitation.pending} fallback={<>Loading...</>}>
|
||||
<Invitation values={invitation.result} />
|
||||
</Show>
|
||||
|
|
Loading…
Reference in New Issue