import Button from '@/components/buttons/Button.vue'
import StateButton from '@/components/buttons/StateButton.vue'
import ToggleButton from '@/components/buttons/ToggleButton.vue'
-import { useUIClient } from '@/composables'
+import { useExecuteAction, useUIClient } from '@/composables'
const props = defineProps<{
atgStatus?: Status
const $toast = useToast()
-const executeAction = (action: Promise<unknown>, successMsg: string, errorMsg: string): void => {
- action
- .then(() => {
- $emit('need-refresh')
- return $toast.success(successMsg)
- })
- .catch((error: Error) => {
- $toast.error(errorMsg)
- console.error(`${errorMsg}:`, error)
- })
-}
+const executeAction = useExecuteAction($emit)
const stopTransaction = (): void => {
if (props.connector.transactionId == null) {
import StateButton from '@/components/buttons/StateButton.vue'
import ToggleButton from '@/components/buttons/ToggleButton.vue'
import CSConnector from '@/components/charging-stations/CSConnector.vue'
-import { deleteFromLocalStorage, getLocalStorage, useUIClient } from '@/composables'
+import {
+ deleteFromLocalStorage,
+ getLocalStorage,
+ useExecuteAction,
+ useUIClient,
+} from '@/composables'
interface ConnectorTableEntry {
connector: ConnectorStatus
const $toast = useToast()
-const executeAction = (action: Promise<unknown>, successMsg: string, errorMsg: string): void => {
- action
- .then(() => {
- $emit('need-refresh')
- return $toast.success(successMsg)
- })
- .catch((error: Error) => {
- $toast.error(errorMsg)
- console.error(`${errorMsg}:`, error)
- })
-}
+const executeAction = useExecuteAction($emit)
const startChargingStation = (): void => {
executeAction(
import type { Ref } from 'vue'
import { getCurrentInstance } from 'vue'
+import { useToast } from 'vue-toast-notification'
import type { ChargingStationData, UUIDv4 } from '@/types'
const response = await useUIClient().listChargingStations()
ref.value = response.chargingStations as ChargingStationData[]
}
+
+export const useExecuteAction = (emit: (event: 'need-refresh') => void) => {
+ const $toast = useToast()
+ return (action: Promise<unknown>, successMsg: string, errorMsg: string): void => {
+ action
+ .then(() => {
+ emit('need-refresh')
+ return $toast.success(successMsg)
+ })
+ .catch((error: unknown) => {
+ $toast.error(errorMsg)
+ console.error(`${errorMsg}:`, error)
+ })
+ }
+}
resetToggleButtonState,
setToLocalStorage,
useChargingStations,
+ useExecuteAction,
useUIClient,
} from './Utils'