refactor(ui): cleanup eslint configuration
[e-mobility-charging-stations-simulator.git] / ui / web / src / components / actions / StartTransaction.vue
index 4d3e818db66fc010b421d635851639f8bde3e11d..a0ab5ceceff52094a03e0b3ca34f1eb1fe46ab5b 100644 (file)
@@ -1,16 +1,21 @@
 <template>
-  <h2>Action Start Transaction</h2>
-  <h3>Connector {{ connectorId }} on {{ chargingStationId }}</h3>
+  <h1 id="action">Start Transaction</h1>
+  <h2>{{ chargingStationId }}</h2>
+  <h3>Connector {{ connectorId }}</h3>
   <p>Scan RFID tag:</p>
-  <input id="idtag" v-model="state.idTag" type="text" name="idtag" placeholder="RFID tag" />
+  <input id="idtag" v-model.trim="state.idTag" type="text" name="idtag" placeholder="RFID tag" />
   <br />
   <Button
+    id="action-button"
     @click="
       () => {
-        uiClient
-          .startTransaction(props.hashId, parseInt(props.connectorId), state.idTag)
+        $uiClient
+          .startTransaction(hashId, convertToInt(connectorId), state.idTag)
+          .then(() => {
+            $toast.success('Transaction successfully started')
+          })
           .catch((error: Error) => {
-            // TODO: add code for UI notifications or other error handling logic
+            $toast.error('Error at starting transaction')
             console.error('Error at starting transaction:', error)
           })
           .finally(() => {
           })
       }
     "
-    >Start Transaction</Button
   >
+    Start Transaction
+  </Button>
 </template>
 
 <script setup lang="ts">
-import { getCurrentInstance, reactive } from 'vue'
+import { ref } from 'vue'
+
 import Button from '@/components/buttons/Button.vue'
+import { convertToInt } from '@/composables'
 
-const props = defineProps<{
+defineProps<{
   hashId: string
   chargingStationId: string
   connectorId: string
 }>()
 
-const state = reactive({
+const state = ref<{ idTag: string }>({
   idTag: ''
 })
-
-const uiClient = getCurrentInstance()?.appContext.config.globalProperties.$uiClient
 </script>
 
 <style>