From 23297b1addb03537271f97ba6d721e5da9305654 Mon Sep 17 00:00:00 2001 From: Punarv Pawade Date: Mon, 22 Jan 2024 00:10:13 +0530 Subject: [PATCH] vpnCard: fix delete route --- components/Myvpncard.tsx | 363 +++++++++++++++++++++++---------------- 1 file changed, 211 insertions(+), 152 deletions(-) diff --git a/components/Myvpncard.tsx b/components/Myvpncard.tsx index 918e758..0c65524 100644 --- a/components/Myvpncard.tsx +++ b/components/Myvpncard.tsx @@ -1,15 +1,12 @@ -"use client" +"use client"; import React, { useState } from "react"; import { saveAs } from "file-saver"; -import { - FaDownload, - FaQrcode, -} from "react-icons/fa"; +import { FaDownload, FaQrcode } from "react-icons/fa"; import axios from "axios"; import Cookies from "js-cookie"; import QrCode from "./qrCode"; -import dlt from '../public/dlt.png'; -import Image from 'next/image'; +import dlt from "../public/dlt.png"; +import Image from "next/image"; const REACT_APP_GATEWAY_URL = process.env.NEXT_PUBLIC_GATEWAY_URL; interface ReviewCardProps { @@ -44,18 +41,25 @@ const backgroundbutton = { backgroundColor: "#11D9C5", }; -const handleDownload = async (clientId: string, name: string, region: string) => { +const handleDownload = async ( + clientId: string, + name: string, + region: string +) => { try { const auth = Cookies.get("erebrus_token"); - const response = await axios.get(`${REACT_APP_GATEWAY_URL}api/v1.0/erebrus/config/${region}/${clientId}`, { - headers: { - Accept: "application/json, text/plain, */*", - "Content-Type": "application/json", - Authorization: `Bearer ${auth}`, - }, - }); - console.log(response) + const response = await axios.get( + `${REACT_APP_GATEWAY_URL}api/v1.0/erebrus/config/${region}/${clientId}`, + { + headers: { + Accept: "application/json, text/plain, */*", + "Content-Type": "application/json", + Authorization: `Bearer ${auth}`, + }, + } + ); + console.log(response); const config = response.data; const blob = new Blob([config], { type: "text/plain;charset=utf-8" }); saveAs(blob, `${name}.conf`); @@ -71,22 +75,16 @@ const MyVpnCard: React.FC = ({ const [showPassword, setShowPassword] = useState(false); const [loading, setLoading] = useState(false); const [delvpn, setdelvpn] = useState(false); - const [qr, setqr]= useState(false); + const [qr, setqr] = useState(false); if (!metaData) { return ( -
+
-
+
); @@ -106,101 +104,105 @@ const MyVpnCard: React.FC = ({ } }; - const deletevpn = async (id: string) => { + const deletevpn = async (id: string, region: string) => { setLoading(true); - + const auth = Cookies.get("erebrus_token"); - - const jsonData = { - "vpnId":id - } - + try { - const response = await fetch(`${REACT_APP_GATEWAY_URL}api/v1.0/vpn`, { - method: 'DELETE', - headers: { - Accept: "application/json, text/plain, */*", - "Content-Type": "application/json", - Authorization: `Bearer ${auth}`, - }, - body: JSON.stringify(jsonData), - }); + const response = await fetch( + `${REACT_APP_GATEWAY_URL}api/erebrus/client/:${id}/${region}`, + { + method: "DELETE", + headers: { + Accept: "application/json, text/plain, */*", + "Content-Type": "application/json", + Authorization: `Bearer ${auth}`, + }, + } + ); console.log(response); - + if (response.status === 200) { - console.log("success") + console.log("success"); setdelvpn(false); // window.location.reload(); } else { } } catch (error) { - console.error('Error:', error); + console.error("Error:", error); } finally { setLoading(false); } }; return ( -
+
-
-
-
-
{metaData.UUID.slice(0, 4)}...{metaData.UUID.slice(-4)}
-
-
- -
- +
+
+
+
+ {metaData.UUID.slice(0, 4)}...{metaData.UUID.slice(-4)}
+
+
-
-
+ -
{ +
+
+
{}}> + +
+
+
- }}> - -
-
- -
- -
- - - -
+
+ + + +
- {/*
+ {/*
{ @@ -223,77 +225,134 @@ const MyVpnCard: React.FC = ({
*/} - -
-
- { - qr && (
-
-
-
-

- Scan QR Code -

-
+
+ {qr && ( +
+
+
+
+

Scan QR Code

+ +
+
- - -
-
-
-) -} +
+
+ )} -{ - delvpn && (
-
-
-
+ {delvpn && ( +
+
+
+

- Are you sure? + Are you sure?

-
-
+
+

- Do you really want to delete this client? -This process can not be undone. + Do you really want to delete this client? This process can not + be undone.

-
-
- -
-
-
-
-) -} +
+ + +
+
+
+
+ )} -{loading && (
-
-
+ {loading && ( +
+
+
{/* */}
-
)} - +
+ )}
); }; -export default MyVpnCard; \ No newline at end of file +export default MyVpnCard;