Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 47 additions & 12 deletions dashboard/src/pages/login/CoreSelectExisting.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import axios from 'axios';
import axios, { AxiosResponse } from 'axios';
import Button from 'components/Atoms/Button';
import { useContext } from 'react';
import { DISABLE_AUTOFILL, errorToString } from 'utils/util';
Expand All @@ -11,12 +11,14 @@ import {
faClone,
faDownload,
faPlus,
faScrewdriverWrench
} from '@fortawesome/free-solid-svg-icons';
import SelectField from 'components/Atoms/Form/SelectField';
import { BrowserLocationContext } from 'data/BrowserLocationContext';
import { CoreInfo } from 'data/SystemInfo';
import { useDocumentTitle } from 'usehooks-ts';
import WarningAlert from 'components/Atoms/WarningAlert';
import { tauri } from 'utils/tauriUtil';
type SelectCoreValue = {
core: CoreConnectionInfo;
};
Expand All @@ -41,17 +43,16 @@ const CoreSelectExisting = () => {
core,
};

const onSubmit = (
values: SelectCoreValue,
actions: FormikHelpers<SelectCoreValue>
) => {
const { core } = values;
// check if core can be reached
const configureCore = (
core: CoreConnectionInfo,
onComplete?: (res: AxiosResponse) => void,
onError?: (res: AxiosResponse) => void
) => {
axios
.get<CoreInfo>(`/info`, {
baseURL: `${core.protocol}://${core.address}:${core.port}/api/${core.apiVersion}`,
})
.then((res) => {
.then(res => {
if (res.status !== 200)
throw new Error('Invalid response, setup may be invalid');
setCore(core);
Expand All @@ -60,14 +61,31 @@ const CoreSelectExisting = () => {
} else {
setPathname('/login/user/select');
}
actions.setSubmitting(false);
return res
})
.then(res => {
(onComplete && typeof onComplete === "function")? onComplete(res) : null
})
.catch(err => {
(onError && typeof onError === "function")? onError(err) : null
})
.catch((err) => {
const errorMessages = errorToString(err);

}

const onSubmit = (
values: SelectCoreValue,
actions: FormikHelpers<SelectCoreValue>
) => {
const { core } = values;
// check if core can be reached
configureCore(core, () => {
actions.setSubmitting(false)
}, (err) => {
const errorMessages = errorToString(err);
actions.setStatus({ error: errorMessages });
actions.setSubmitting(false);
return;
});
})
};

return (
Expand Down Expand Up @@ -133,6 +151,23 @@ const CoreSelectExisting = () => {
);
}}
/>
{
tauri && <Button
type="button"
iconRight={faScrewdriverWrench}
label="Use local Core"
onClick={() => {
const core = {
protocol: 'http',
address: 'localhost',
port: '16662',
apiVersion: 'v1'
}
configureCore(core)
}}
/>
}

<Button
type="submit"
intention="primary"
Expand Down
8 changes: 5 additions & 3 deletions dashboard/src/pages/login/CoreSetupNew.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,14 @@ const CoreSetupNew = () => {
/>
</div>
<div className="flex w-full flex-row justify-end gap-4">
{/* <Button
<Button
type="button"
iconRight={faArrowLeft}
label="Back"
onClick={navigateBack}
/> */}
onClick={() => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this be shortened to onClick={navigateBack}?

navigateBack()
}}
/>
<Button
type="submit"
intention="primary"
Expand Down
42 changes: 29 additions & 13 deletions dashboard/src/pages/login/FirstTime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ const FirstTime = () => {
const [tauriIsSetup, setTauriIsSetup] = useState(false);

useEffectOnce(() => {
if (coreList.length > 0) {
setPathname('/login/core/select');
return;
}

// if (coreList.length > 0) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this redirect commented out?

// console.log({coreList})
// setPathname('/login/core/select');
// console.log("redirecting to /login/core/select")
// return;
// }
if (!tauri) return;
tauri
.invoke<string | null>('is_setup')
Expand All @@ -27,7 +30,7 @@ const FirstTime = () => {
setCore(DEFAULT_LOCAL_CORE);
setTauriIsSetup(is_setup === 'true');
})
.catch((err: any) => {
.catch((err: Error) => {
console.error('Tauri call failed is_setup', err);
});
});
Expand Down Expand Up @@ -95,7 +98,7 @@ const FirstTime = () => {
<Button
label="Connect to existing Core"
onClick={() => setPathname('/login/core/new')}
intention="primary"
intention="info"
size="large"
className="whitespace-nowrap"
/>
Expand All @@ -109,13 +112,26 @@ const FirstTime = () => {
className="whitespace-nowrap"
/>
) : (
<Button
label="Setup Lodestone Core"
onClick={() => setPathname('/login/core/first_setup')}
intention="primary"
size="large"
className="whitespace-nowrap"
/>
<>
<Button
label="Use local core"
onClick={() => setPathname('/login/core/first_setup')}
intention="primary"
size="large"
className="whitespace-nowrap"
/>
<Button
label="Connect to existing core"
onClick = {() => {
setPathname('/login/core/select')
}}
intention = 'primary'
size = "large"
className="whitespace-nowrap"
/>

</>

)}
</div>
</div>
Expand Down