Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Update instance info if exists #19

Merged
merged 2 commits into from
Sep 29, 2023
Merged
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
3 changes: 2 additions & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use tauri::{Manager, State};
use tauri::SystemTrayEvent;
mod tray;
use crate::commands::{
all_instances, all_locations, connect, disconnect, location_stats, save_device_config,
all_instances, all_locations, connect, disconnect, location_stats, save_device_config, update_instance
};
use crate::tray::create_tray_menu;

Expand All @@ -36,6 +36,7 @@ fn main() {
all_instances,
connect,
disconnect,
update_instance,
location_stats,
])
.on_window_event(|event| match event.event() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { zodResolver } from '@hookform/resolvers/zod';
import { Body, fetch, Response } from '@tauri-apps/api/http';
import { invoke } from '@tauri-apps/api/tauri';
import dayjs from 'dayjs';
import { isUndefined } from 'lodash-es';
import { useMemo } from 'react';
import { SubmitHandler, useForm } from 'react-hook-form';
import { useNavigate } from 'react-router-dom';
Expand Down Expand Up @@ -61,9 +61,6 @@ export const AddInstanceModalInitStep = () => {
const handleValidSubmit: SubmitHandler<FormFields> = async (values) => {
const url = () => {
const endpoint = '/api/v1/enrollment/start';
if (import.meta.env.DEV) {
return endpoint;
}
let base: string;
if (values.url[values.url.length - 1] === '/') {
base = values.url.slice(0, -1);
Expand All @@ -75,7 +72,7 @@ export const AddInstanceModalInitStep = () => {

const endpointUrl = url();

const headers = {
const headers: Record<string, string> = {
'Content-Type': 'application/json',
};

Expand All @@ -85,7 +82,7 @@ export const AddInstanceModalInitStep = () => {

setModalState({ loading: true });

fetch(endpointUrl, {
fetch<EnrollmentStartResponse>(endpointUrl, {
method: 'POST',
headers,
body: Body.json(data),
Expand All @@ -111,14 +108,28 @@ export const AddInstanceModalInitStep = () => {
if (instance) {
// update already registered instance instead
headers['Cookie'] = authCookie;
const instanceInfo = await fetch(`${proxy_api_url}/enrollment/network_info`, {
fetch<CreateDeviceResponse>(`${proxy_api_url}/enrollment/network_info`, {
method: 'POST',
headers,
body: Body.json({
pubkey: instance.pubkey,
}),
}).then(async (res) => {
invoke<void>('update_instance', {
instanceId: instance.id,
response: res.data,
})
.then(() => {
toaster.success(
LL.pages.enrollment.steps.deviceSetup.desktopSetup.messages.deviceConfigured(),
);
closeModal();
})
.catch((e) => {
console.error(e);
toaster.error(LL.pages.client.modals.addInstanceModal.messages.error());
});
});
return;
}
// register new instance
// is user in need of full enrollment ?
Expand Down
8 changes: 0 additions & 8 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@ export default defineConfig({
server: {
strictPort: true,
port: 3000,
proxy: {
'/api': {
target: 'http://127.0.0.1:8080',
changeOrigin: true,
secure: false,
ws: true,
},
},
},
resolve: {
alias: {
Expand Down
Loading