From 577a52efe4cbce3ebc57cd54d1a330a2ca9c2648 Mon Sep 17 00:00:00 2001 From: dzania Date: Thu, 28 Sep 2023 16:16:47 +0200 Subject: [PATCH 1/2] Add update instance --- src-tauri/src/main.rs | 3 +- .../steps/AddInstanceInitStep.tsx | 28 +++++++++++++------ vite.config.ts | 8 ------ 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 3e123866..cd5dc22b 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -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; @@ -36,6 +36,7 @@ fn main() { all_instances, connect, disconnect, + update_instance, location_stats, ]) .on_window_event(|event| match event.event() { diff --git a/src/pages/client/components/modals/AddInstanceModal/steps/AddInstanceInitStep.tsx b/src/pages/client/components/modals/AddInstanceModal/steps/AddInstanceInitStep.tsx index 634bbd26..5d7ca896 100644 --- a/src/pages/client/components/modals/AddInstanceModal/steps/AddInstanceInitStep.tsx +++ b/src/pages/client/components/modals/AddInstanceModal/steps/AddInstanceInitStep.tsx @@ -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'; @@ -61,9 +61,6 @@ export const AddInstanceModalInitStep = () => { const handleValidSubmit: SubmitHandler = 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); @@ -75,7 +72,7 @@ export const AddInstanceModalInitStep = () => { const endpointUrl = url(); - const headers = { + const headers: Record = { 'Content-Type': 'application/json', }; @@ -85,7 +82,7 @@ export const AddInstanceModalInitStep = () => { setModalState({ loading: true }); - fetch(endpointUrl, { + fetch(endpointUrl, { method: 'POST', headers, body: Body.json(data), @@ -111,14 +108,29 @@ export const AddInstanceModalInitStep = () => { if (instance) { // update already registered instance instead headers['Cookie'] = authCookie; - const instanceInfo = await fetch(`${proxy_api_url}/enrollment/network_info`, { + fetch(`${proxy_api_url}/enrollment/network_info`, { method: 'POST', headers, body: Body.json({ pubkey: instance.pubkey, }), + }).then(async (res) => { + console.log('here', res.data); + invoke('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 ? diff --git a/vite.config.ts b/vite.config.ts index c0d846d1..2d791cb0 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -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: { From e841008e1f4874b6b4d917c40b1428287dc2dc97 Mon Sep 17 00:00:00 2001 From: dzania Date: Thu, 28 Sep 2023 16:18:23 +0200 Subject: [PATCH 2/2] remove console.log --- .../modals/AddInstanceModal/steps/AddInstanceInitStep.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/client/components/modals/AddInstanceModal/steps/AddInstanceInitStep.tsx b/src/pages/client/components/modals/AddInstanceModal/steps/AddInstanceInitStep.tsx index 5d7ca896..aaaa260b 100644 --- a/src/pages/client/components/modals/AddInstanceModal/steps/AddInstanceInitStep.tsx +++ b/src/pages/client/components/modals/AddInstanceModal/steps/AddInstanceInitStep.tsx @@ -115,7 +115,6 @@ export const AddInstanceModalInitStep = () => { pubkey: instance.pubkey, }), }).then(async (res) => { - console.log('here', res.data); invoke('update_instance', { instanceId: instance.id, response: res.data,