feat user restriction

This commit is contained in:
Quan HL
2023-11-07 14:06:49 +07:00
parent 28ddf0faf2
commit b3a1965be2
3 changed files with 135 additions and 85 deletions

View File

@@ -3,6 +3,7 @@ import {
FetchError,
FetchTransport,
Queue,
RegisteredUser,
StatusCodes,
} from "./types";
import { MSG_SOMETHING_WRONG } from "./constants";
@@ -144,3 +145,10 @@ export const getQueues = () => {
`${advancedSettings.apiServer}/Accounts/${advancedSettings.accountSid}/Queues`
);
};
export const getSelfRegisteredUser = (username: string) => {
const advancedSettings = getAdvancedSettings();
return getFetch<RegisteredUser>(
`${advancedSettings.apiServer}/Accounts/${advancedSettings.accountSid}/RegisteredSipUsers/${username}`
);
};

View File

@@ -34,3 +34,14 @@ export interface Queue {
name: string;
length: number;
}
export interface RegisteredUser {
name: string;
contact: string;
expiryTime: number;
protocol: string;
allow_direct_app_calling: boolean;
allow_direct_queue_calling: boolean;
allow_direct_user_calling: boolean;
registered_status: string;
}

View File

@@ -52,9 +52,15 @@ import {
import { OutGoingCall } from "./outgoing-call";
import { v4 as uuidv4 } from "uuid";
import IconButtonMenu, { IconButtonMenuItems } from "src/components/menu";
import { getApplications, getQueues, getRegisteredUser } from "src/api";
import {
getApplications,
getQueues,
getRegisteredUser,
getSelfRegisteredUser,
} from "src/api";
import JambonzSwitch from "src/components/switch";
import { DEFAULT_TOAST_DURATION } from "src/common/constants";
import { RegisteredUser } from "src/api/types";
type PhoneProbs = {
sipDomain: string;
@@ -100,6 +106,13 @@ export const Phone = ({
const sipDisplayNameRef = useRef("");
const [isForceChangeUaStatus, setIsForceChangeUaStatus] = useState(false);
const isInputNumberFocusRef = useRef(false);
const [registeredUser, setRegisteredUser] = useState<Partial<RegisteredUser>>(
{
allow_direct_app_calling: false,
allow_direct_queue_calling: false,
allow_direct_user_calling: false,
}
);
const toast = useToast();
useEffect(() => {
@@ -162,6 +175,17 @@ export const Phone = ({
}
}, [status]);
useEffect(() => {
getSelfRegisteredUser(sipUsernameRef.current).then(({ json }) => {
setRegisteredUser(json);
});
setInterval(() => {
getSelfRegisteredUser(sipUsernameRef.current).then(({ json }) => {
setRegisteredUser(json);
});
}, 20000);
}, []);
// useEffect(() => {
// chrome.runtime.onMessage.addListener(function (request) {
// const msg = request as Message<any>;
@@ -478,6 +502,7 @@ export const Phone = ({
>
{isAdvanceMode && isSipClientIdle(callStatus) && (
<HStack spacing={2} align="start" w="full">
{registeredUser.allow_direct_user_calling && (
<IconButtonMenu
icon={<Users />}
tooltip="Call an online user"
@@ -508,6 +533,9 @@ export const Phone = ({
);
}}
/>
)}
{registeredUser.allow_direct_queue_calling && (
<IconButtonMenu
icon={<List />}
tooltip="Take a call from queue"
@@ -535,7 +563,9 @@ export const Phone = ({
);
}}
/>
)}
{registeredUser.allow_direct_app_calling && (
<IconButtonMenu
icon={<GitMerge />}
tooltip="Call an application"
@@ -563,6 +593,7 @@ export const Phone = ({
);
}}
/>
)}
</HStack>
)}