Skip to content

Commit

Permalink
Add update instance
Browse files Browse the repository at this point in the history
  • Loading branch information
dzania committed Sep 28, 2023
1 parent 36f9f05 commit 577a52e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
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,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<CreateDeviceResponse>(`${proxy_api_url}/enrollment/network_info`, {
method: 'POST',
headers,
body: Body.json({
pubkey: instance.pubkey,
}),
}).then(async (res) => {
console.log('here', res.data);
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

0 comments on commit 577a52e

Please sign in to comment.