import React, {useEffect, useState} from "react"; import { useNavigate, useParams } from "react-router-dom"; import { AuthService, CenterPhoneService } from "../../services"; import { Spinner, Breadcrumb, BreadcrumbItem, Tabs, Tab } from "react-bootstrap"; const UpdateCenterPhone = () => { const navigate = useNavigate(); const [phoneTitle, setPhoneTitle] = useState(''); const [phoneNumber, setPhoneNumber] = useState(''); const [activated, setActivated] = useState(false); const [currentPhone, setCurrentPhone] = useState(undefined); const urlParams = useParams(); useEffect(() => { if (!AuthService.canAddOrEditRoutes() && !AuthService.canViewRoutes()&&!AuthService.canAccessLegacySystem()) { window.alert('You haven\'t login yet OR this user does not have access to this page. Please change an Dispatcher or admin account to login.') AuthService.logout(); navigate(`/login`); } if (!currentPhone) { CenterPhoneService.getCenterPhone(urlParams.id).then(data => setCurrentPhone(data.data)) } }, []); useEffect(() => { if (currentPhone) { setPhoneNumber(currentPhone.phone_number); setPhoneTitle(currentPhone.phone_title); setActivated(currentPhone.activated); } }, [currentPhone]) const redirectTo = () => { navigate('/center-phones/list') } const savePhone = () => { const data = { phone_title: phoneTitle, phone_number: phoneNumber, activated: activated }; CenterPhoneService.updateCenterPhone(urlParams.id, data).then(() => redirectTo()) } return ( <>