refactor(ui): cleanup CSS styling
[e-mobility-charging-stations-simulator.git] / ui / web / src / components / charging-stations / CSConnector.vue
index c9e53696cde361b52feecbb020ec22200c21c6b8..36bb971f6c3e0316a3432643aedb4b9463a26e6a 100644 (file)
@@ -9,15 +9,30 @@
       {{ atgStatus?.start === true ? 'Yes' : 'No' }}
     </td>
     <td class="connectors-table__column">
-      <Button
-        @click="
-          $router.push({
-            name: 'start-transaction',
-            params: { hashId, chargingStationId, connectorId }
-          })
+      <ToggleButton
+        :id="`${hashId}-${connectorId}-start-transaction`"
+        :shared="true"
+        :on="
+          () => {
+            $router.push({
+              name: 'start-transaction',
+              params: { hashId, chargingStationId, connectorId }
+            })
+          }
+        "
+        :off="
+          () => {
+            $router.push({ name: 'charging-stations' })
+          }
+        "
+        @clicked="
+          () => {
+            $emit('need-refresh')
+          }
         "
-        >Start Transaction</Button
       >
+        Start Transaction
+      </ToggleButton>
       <Button @click="stopTransaction()">Stop Transaction</Button>
       <Button @click="startAutomaticTransactionGenerator()">Start ATG</Button>
       <Button @click="stopAutomaticTransactionGenerator()">Stop ATG</Button>
 
 <script setup lang="ts">
 import { getCurrentInstance } from 'vue'
+import { useToast } from 'vue-toast-notification'
 import Button from '@/components/buttons/Button.vue'
 import type { ConnectorStatus, Status } from '@/types'
+import ToggleButton from '@/components/buttons/ToggleButton.vue'
 
 const props = defineProps<{
   hashId: string
@@ -38,15 +55,43 @@ const props = defineProps<{
   atgStatus?: Status
 }>()
 
+const $emit = defineEmits(['need-refresh'])
+
 const uiClient = getCurrentInstance()?.appContext.config.globalProperties.$uiClient
 
-function stopTransaction(): void {
-  uiClient.stopTransaction(props.hashId, props.connector.transactionId)
+const $toast = useToast()
+
+const stopTransaction = (): void => {
+  uiClient
+    .stopTransaction(props.hashId, props.connector.transactionId)
+    .then(() => {
+      $toast.success('Transaction successfully stopped')
+    })
+    .catch((error: Error) => {
+      $toast.error('Error at stopping transaction')
+      console.error('Error at stopping transaction:', error)
+    })
 }
-function startAutomaticTransactionGenerator(): void {
-  uiClient.startAutomaticTransactionGenerator(props.hashId, props.connectorId)
+const startAutomaticTransactionGenerator = (): void => {
+  uiClient
+    .startAutomaticTransactionGenerator(props.hashId, props.connectorId)
+    .then(() => {
+      $toast.success('Automatic transaction generator successfully started')
+    })
+    .catch((error: Error) => {
+      $toast.error('Error at starting automatic transaction generator')
+      console.error('Error at starting automatic transaction generator:', error)
+    })
 }
-function stopAutomaticTransactionGenerator(): void {
-  uiClient.stopAutomaticTransactionGenerator(props.hashId, props.connectorId)
+const stopAutomaticTransactionGenerator = (): void => {
+  uiClient
+    .stopAutomaticTransactionGenerator(props.hashId, props.connectorId)
+    .then(() => {
+      $toast.success('Automatic transaction generator successfully stopped')
+    })
+    .catch((error: Error) => {
+      $toast.error('Error at stopping automatic transaction generator')
+      console.error('Error at stopping automatic transaction generator:', error)
+    })
 }
 </script>