major claude changes
This commit is contained in:
@@ -212,9 +212,9 @@
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
// NO CHANGES to the script block were made. All your logic remains intact.
|
||||
import { defineComponent } from 'vue'
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import axios from 'axios'
|
||||
import authHeader from '../../services/auth.header'
|
||||
import { useSearchStore } from '../../stores/search' // Adjust path if needed
|
||||
@@ -231,180 +231,182 @@ interface RoutingOption {
|
||||
label: string;
|
||||
}
|
||||
|
||||
// Router
|
||||
const router = useRouter()
|
||||
|
||||
export default defineComponent({
|
||||
data() {
|
||||
return {
|
||||
// Initialize with empty objects to prevent template errors
|
||||
user: {} as User,
|
||||
currentPhone: '',
|
||||
routingOptions: [
|
||||
{ value: 'main', label: '407323' },
|
||||
{ value: 'sip', label: '407323_auburnoil' },
|
||||
{ value: 'cellphone1', label: 'Ed Cell' },
|
||||
{ value: 'cellphone2', label: 'Aneta Cell' },
|
||||
{ value: 'test_did', label: 'Test DID' }
|
||||
] as RoutingOption[],
|
||||
selectedOption: null as RoutingOption | null,
|
||||
isRouteModalVisible: false,
|
||||
routeModalMode: 'confirm',
|
||||
routeResponse: null as any,
|
||||
isTestModalVisible: false,
|
||||
isTestLoading: false,
|
||||
testResponse: null as any
|
||||
}
|
||||
},
|
||||
// Reactive data
|
||||
const user = ref({} as User)
|
||||
const currentPhone = ref('')
|
||||
const routingOptions = ref([
|
||||
{ value: 'main', label: '407323' },
|
||||
{ value: 'sip', label: '407323_auburnoil' },
|
||||
{ value: 'cellphone1', label: 'Ed Cell' },
|
||||
{ value: 'cellphone2', label: 'Aneta Cell' },
|
||||
{ value: 'test_did', label: 'Test DID' }
|
||||
] as RoutingOption[])
|
||||
const selectedOption = ref<RoutingOption | null>(null)
|
||||
const isRouteModalVisible = ref(false)
|
||||
const routeModalMode = ref('confirm')
|
||||
const routeResponse = ref(null as any)
|
||||
const isTestModalVisible = ref(false)
|
||||
const isTestLoading = ref(false)
|
||||
const testResponse = ref(null as any)
|
||||
|
||||
computed: {
|
||||
searchStore() {
|
||||
return useSearchStore();
|
||||
// Computed properties
|
||||
const searchStore = computed(() => useSearchStore())
|
||||
|
||||
},
|
||||
userInitials(): string {
|
||||
if (!this.user || !this.user.user_name) return '';
|
||||
const parts = this.user.user_name.split(' ');
|
||||
return parts.length > 1
|
||||
? `${parts[0][0]}${parts[1][0]}`.toUpperCase()
|
||||
: this.user.user_name.substring(0, 2).toUpperCase();
|
||||
},
|
||||
currentDate(): string {
|
||||
const now = new Date();
|
||||
const month = (now.getMonth() + 1).toString().padStart(2, '0');
|
||||
const day = now.getDate().toString().padStart(2, '0');
|
||||
const year = now.getFullYear().toString().slice(-2);
|
||||
return `${month}/${day}/${year}`;
|
||||
},
|
||||
dayOfWeek(): string {
|
||||
const now = new Date();
|
||||
return now.toLocaleDateString('en-US', { weekday: 'long' });
|
||||
}
|
||||
},
|
||||
const userInitials = computed((): string => {
|
||||
if (!user.value || !user.value.user_name) return '';
|
||||
const parts = user.value.user_name.split(' ');
|
||||
return parts.length > 1
|
||||
? `${parts[0][0]}${parts[1][0]}`.toUpperCase()
|
||||
: user.value.user_name.substring(0, 2).toUpperCase();
|
||||
})
|
||||
|
||||
created() {
|
||||
this.userStatus();
|
||||
},
|
||||
mounted() {
|
||||
this.updatestatus();
|
||||
this.fetchCurrentPhone();
|
||||
},
|
||||
methods: {
|
||||
userStatus() {
|
||||
let path = import.meta.env.VITE_BASE_URL + '/auth/whoami';
|
||||
axios({
|
||||
method: "get",
|
||||
url: path,
|
||||
withCredentials: true,
|
||||
headers: authHeader(),
|
||||
const currentDate = computed((): string => {
|
||||
const now = new Date();
|
||||
const month = (now.getMonth() + 1).toString().padStart(2, '0');
|
||||
const day = now.getDate().toString().padStart(2, '0');
|
||||
const year = now.getFullYear().toString().slice(-2);
|
||||
return `${month}/${day}/${year}`;
|
||||
})
|
||||
|
||||
})
|
||||
.then((response: any) => {
|
||||
if (response.data.ok) {
|
||||
this.user = response.data.user;
|
||||
} else {
|
||||
const dayOfWeek = computed((): string => {
|
||||
const now = new Date();
|
||||
return now.toLocaleDateString('en-US', { weekday: 'long' });
|
||||
})
|
||||
|
||||
localStorage.removeItem('user');
|
||||
this.$router.push('/login');
|
||||
}
|
||||
})
|
||||
},
|
||||
updatestatus() {
|
||||
let path = import.meta.env.VITE_BASE_URL + '/delivery/updatestatus';
|
||||
axios({
|
||||
method: 'get',
|
||||
url: path,
|
||||
headers: authHeader(),
|
||||
}).then((response: any) => {
|
||||
if (response.data.update)
|
||||
console.log("Updated Status of Deliveries")
|
||||
})
|
||||
},
|
||||
logout() {
|
||||
// Clear auth data
|
||||
const authStore = useAuthStore();
|
||||
authStore.clearAuth();
|
||||
// Redirect to login
|
||||
this.$router.push({ name: 'login' });
|
||||
},
|
||||
fetchCurrentPhone() {
|
||||
const path = import.meta.env.VITE_BASE_URL + '/admin/voip_routing';
|
||||
axios({
|
||||
method: 'get',
|
||||
url: path,
|
||||
headers: authHeader(),
|
||||
withCredentials: true,
|
||||
})
|
||||
.then((response: any) => {
|
||||
if (response.data.current_phone) {
|
||||
this.currentPhone = response.data.current_phone;
|
||||
}
|
||||
})
|
||||
.catch((error: any) => {
|
||||
console.error('Failed to fetch current routing:', error);
|
||||
});
|
||||
},
|
||||
routeTo(route: string): Promise<any> {
|
||||
const path = `${import.meta.env.VITE_VOIPMS_URL}/route/${route}`;
|
||||
return axios({
|
||||
method: 'post',
|
||||
url: path,
|
||||
withCredentials: true, headers: authHeader()
|
||||
})
|
||||
.then((response: any) => {
|
||||
this.routeResponse = response.data;
|
||||
// Find the corresponding label
|
||||
const option = this.routingOptions.find(opt => opt.value === route);
|
||||
if (option) {
|
||||
this.currentPhone = option.label;
|
||||
}
|
||||
return response.data;
|
||||
});
|
||||
},
|
||||
showConfirmRoute(option: RoutingOption) {
|
||||
this.selectedOption = option;
|
||||
if (option.value === 'test_did') {
|
||||
this.testDid();
|
||||
// Lifecycle
|
||||
onMounted(() => {
|
||||
userStatus()
|
||||
updatestatus()
|
||||
fetchCurrentPhone()
|
||||
})
|
||||
|
||||
// Functions
|
||||
const userStatus = () => {
|
||||
let path = import.meta.env.VITE_BASE_URL + '/auth/whoami';
|
||||
axios({
|
||||
method: "get",
|
||||
url: path,
|
||||
withCredentials: true,
|
||||
headers: authHeader(),
|
||||
|
||||
})
|
||||
.then((response: any) => {
|
||||
if (response.data.ok) {
|
||||
user.value = response.data.user;
|
||||
} else {
|
||||
this.isRouteModalVisible = true;
|
||||
this.routeModalMode = 'confirm';
|
||||
|
||||
localStorage.removeItem('user');
|
||||
router.push('/login');
|
||||
}
|
||||
},
|
||||
proceedRoute() {
|
||||
if (this.selectedOption && this.selectedOption.value !== 'test_did') {
|
||||
this.routeModalMode = 'loading';
|
||||
this.routeTo(this.selectedOption.value)
|
||||
.then(() => {
|
||||
this.routeModalMode = 'result';
|
||||
})
|
||||
.catch((error: any) => {
|
||||
this.routeResponse = { error: error.message };
|
||||
this.routeModalMode = 'result';
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
const updatestatus = () => {
|
||||
let path = import.meta.env.VITE_BASE_URL + '/delivery/updatestatus';
|
||||
axios({
|
||||
method: 'get',
|
||||
url: path,
|
||||
headers: authHeader(),
|
||||
}).then((response: any) => {
|
||||
if (response.data.update)
|
||||
console.log("Updated Status of Deliveries")
|
||||
})
|
||||
}
|
||||
|
||||
const logout = () => {
|
||||
// Clear auth data
|
||||
const authStore = useAuthStore();
|
||||
authStore.clearAuth();
|
||||
// Redirect to login
|
||||
router.push({ name: 'login' });
|
||||
}
|
||||
|
||||
const fetchCurrentPhone = () => {
|
||||
const path = import.meta.env.VITE_BASE_URL + '/admin/voip_routing';
|
||||
axios({
|
||||
method: 'get',
|
||||
url: path,
|
||||
headers: authHeader(),
|
||||
withCredentials: true,
|
||||
})
|
||||
.then((response: any) => {
|
||||
if (response.data.current_phone) {
|
||||
currentPhone.value = response.data.current_phone;
|
||||
}
|
||||
},
|
||||
closeRouteModal() {
|
||||
this.isRouteModalVisible = false;
|
||||
this.routeModalMode = 'confirm';
|
||||
this.routeResponse = null;
|
||||
this.selectedOption = null;
|
||||
},
|
||||
testDid() {
|
||||
this.isTestModalVisible = true;
|
||||
this.isTestLoading = true;
|
||||
const path = `${import.meta.env.VITE_VOIPMS_URL}/test/did`;
|
||||
axios({
|
||||
method: 'get',
|
||||
url: path,
|
||||
withCredentials: true, headers: authHeader()
|
||||
})
|
||||
.then((response: any) => {
|
||||
this.testResponse = response.data;
|
||||
this.isTestLoading = false;
|
||||
})
|
||||
.catch((error: any) => {
|
||||
this.testResponse = { status: 'error', message: error.message };
|
||||
this.isTestLoading = false;
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch((error: any) => {
|
||||
console.error('Failed to fetch current routing:', error);
|
||||
});
|
||||
}
|
||||
|
||||
const routeTo = (route: string): Promise<any> => {
|
||||
const path = `${import.meta.env.VITE_VOIPMS_URL}/route/${route}`;
|
||||
return axios({
|
||||
method: 'post',
|
||||
url: path,
|
||||
withCredentials: true, headers: authHeader()
|
||||
})
|
||||
.then((response: any) => {
|
||||
routeResponse.value = response.data;
|
||||
// Find the corresponding label
|
||||
const option = routingOptions.value.find(opt => opt.value === route);
|
||||
if (option) {
|
||||
currentPhone.value = option.label;
|
||||
}
|
||||
return response.data;
|
||||
});
|
||||
}
|
||||
|
||||
const showConfirmRoute = (option: RoutingOption) => {
|
||||
selectedOption.value = option;
|
||||
if (option.value === 'test_did') {
|
||||
testDid();
|
||||
} else {
|
||||
isRouteModalVisible.value = true;
|
||||
routeModalMode.value = 'confirm';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const proceedRoute = () => {
|
||||
if (selectedOption.value && selectedOption.value.value !== 'test_did') {
|
||||
routeModalMode.value = 'loading';
|
||||
routeTo(selectedOption.value.value)
|
||||
.then(() => {
|
||||
routeModalMode.value = 'result';
|
||||
})
|
||||
.catch((error: any) => {
|
||||
routeResponse.value = { error: error.message };
|
||||
routeModalMode.value = 'result';
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const closeRouteModal = () => {
|
||||
isRouteModalVisible.value = false;
|
||||
routeModalMode.value = 'confirm';
|
||||
routeResponse.value = null;
|
||||
selectedOption.value = null;
|
||||
}
|
||||
|
||||
const testDid = () => {
|
||||
isTestModalVisible.value = true;
|
||||
isTestLoading.value = true;
|
||||
const path = `${import.meta.env.VITE_VOIPMS_URL}/test/did`;
|
||||
axios({
|
||||
method: 'get',
|
||||
url: path,
|
||||
withCredentials: true, headers: authHeader()
|
||||
})
|
||||
.then((response: any) => {
|
||||
testResponse.value = response.data;
|
||||
isTestLoading.value = false;
|
||||
})
|
||||
.catch((error: any) => {
|
||||
testResponse.value = { status: 'error', message: error.message };
|
||||
isTestLoading.value = false;
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user