mirror of
https://github.com/jambonz/jambonz-webapp.git
synced 2026-07-24 13:02:21 +00:00
apply 1st review comments
This commit is contained in:
@@ -440,7 +440,10 @@ export const CarrierForm = ({
|
||||
const handleSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
|
||||
if (user?.scope === USER_ACCOUNT && user.account_sid !== accountSid) {
|
||||
if (
|
||||
user?.scope === USER_ACCOUNT &&
|
||||
(user.account_sid !== accountSid || !accountSid)
|
||||
) {
|
||||
toastError("You do not have permissions to make changes to this Carrier");
|
||||
return;
|
||||
}
|
||||
@@ -722,7 +725,13 @@ export const CarrierForm = ({
|
||||
label="Used By"
|
||||
required={false}
|
||||
defaultOption={checkOptions()}
|
||||
disabled={!!checkOptions()}
|
||||
disabled={
|
||||
user?.scope !== USER_ACCOUNT
|
||||
? false
|
||||
: user.account_sid !== accountSid
|
||||
? true
|
||||
: false
|
||||
}
|
||||
/>
|
||||
{accountSid && hasLength(applications) && (
|
||||
<>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { useState, useMemo } from "react";
|
||||
import React, { useState, useMemo, useEffect } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { Button, H1, Icon, M } from "jambonz-ui";
|
||||
import {
|
||||
@@ -19,6 +19,8 @@ import {
|
||||
} from "src/components";
|
||||
import { hasLength, hasValue, useFilteredResults } from "src/utils";
|
||||
import {
|
||||
API_ACCOUNTS,
|
||||
API_SERVICE_PROVIDERS,
|
||||
API_SIP_GATEWAY,
|
||||
API_SMPP_GATEWAY,
|
||||
USER_ACCOUNT,
|
||||
@@ -30,8 +32,9 @@ import { Gateways } from "./gateways";
|
||||
|
||||
export const Carriers = () => {
|
||||
const user = useSelectState("user");
|
||||
const currentServiceProvider = useSelectState("currentServiceProvider");
|
||||
const [carrier, setCarrier] = useState<Carrier | null>(null);
|
||||
const [carriers, refetch] = useServiceProviderData<Carrier[]>("VoipCarriers");
|
||||
const [carriers, setCarriers] = useState<Carrier[]>();
|
||||
const [accounts] = useServiceProviderData<Account[]>("Accounts");
|
||||
const [accountSid, setAccountSid] = useState("");
|
||||
const [filter, setFilter] = useState("");
|
||||
@@ -44,13 +47,23 @@ export const Carriers = () => {
|
||||
: carrier.account_sid === null
|
||||
)
|
||||
: [];
|
||||
}, [accountSid, carriers]);
|
||||
}, [accountSid, carrier, carriers]);
|
||||
|
||||
const filteredCarriers = useFilteredResults<Carrier>(
|
||||
filter,
|
||||
carriersFiltered
|
||||
);
|
||||
|
||||
const getCarriers = (url: string) => {
|
||||
getFetch<Carrier[]>(url)
|
||||
.then(({ json }) => {
|
||||
setCarriers(json);
|
||||
})
|
||||
.catch((error) => {
|
||||
toastError(error.msg);
|
||||
});
|
||||
};
|
||||
|
||||
const handleDelete = () => {
|
||||
if (carrier) {
|
||||
if (user?.scope === USER_ACCOUNT && user.account_sid !== accountSid) {
|
||||
@@ -87,7 +100,15 @@ export const Carriers = () => {
|
||||
)
|
||||
);
|
||||
});
|
||||
refetch();
|
||||
if ((user && user?.scope === USER_ACCOUNT) || accountSid) {
|
||||
getCarriers(
|
||||
`${API_ACCOUNTS}/${user?.account_sid || accountSid}/VoipCarriers`
|
||||
);
|
||||
} else {
|
||||
getCarriers(
|
||||
`${API_SERVICE_PROVIDERS}/${currentServiceProvider?.service_provider_sid}/VoipCarriers`
|
||||
);
|
||||
}
|
||||
setCarrier(null);
|
||||
toastSuccess(
|
||||
<>
|
||||
@@ -101,6 +122,20 @@ export const Carriers = () => {
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (accountSid) {
|
||||
getCarriers(
|
||||
`${API_ACCOUNTS}/${user?.account_sid || accountSid}/VoipCarriers`
|
||||
);
|
||||
} else {
|
||||
if (currentServiceProvider) {
|
||||
getCarriers(
|
||||
`${API_SERVICE_PROVIDERS}/${currentServiceProvider.service_provider_sid}/VoipCarriers`
|
||||
);
|
||||
}
|
||||
}
|
||||
}, [user, accountSid, currentServiceProvider]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<section className="mast">
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
putPhoneNumber,
|
||||
useServiceProviderData,
|
||||
} from "src/api";
|
||||
import { toastError, toastSuccess } from "src/store";
|
||||
import { toastError, toastSuccess, useSelectState } from "src/store";
|
||||
import {
|
||||
Icons,
|
||||
Section,
|
||||
@@ -30,8 +30,10 @@ import {
|
||||
import { DeletePhoneNumber } from "./delete";
|
||||
|
||||
import type { Account, PhoneNumber, Carrier, Application } from "src/api/types";
|
||||
import { USER_ACCOUNT } from "src/api/constants";
|
||||
|
||||
export const PhoneNumbers = () => {
|
||||
const user = useSelectState("user");
|
||||
const [accounts] = useServiceProviderData<Account[]>("Accounts");
|
||||
const [applications] = useServiceProviderData<Application[]>("Applications");
|
||||
const [carriers] = useServiceProviderData<Carrier[]>("VoipCarriers");
|
||||
@@ -123,7 +125,13 @@ export const PhoneNumbers = () => {
|
||||
/>
|
||||
<AccountFilter
|
||||
account={[accountSid, setAccountSid]}
|
||||
accounts={accounts}
|
||||
accounts={
|
||||
user?.scope === USER_ACCOUNT
|
||||
? accounts?.filter(
|
||||
(acct) => acct.account_sid === user.account_sid
|
||||
)
|
||||
: accounts
|
||||
}
|
||||
defaultOption
|
||||
/>
|
||||
</section>
|
||||
|
||||
@@ -3,8 +3,12 @@ import { ButtonGroup, H1, M, MS } from "jambonz-ui";
|
||||
import dayjs from "dayjs";
|
||||
|
||||
import { getRecentCalls, useServiceProviderData } from "src/api";
|
||||
import { DATE_SELECTION, PER_PAGE_SELECTION } from "src/api/constants";
|
||||
import { toastError } from "src/store";
|
||||
import {
|
||||
DATE_SELECTION,
|
||||
PER_PAGE_SELECTION,
|
||||
USER_ACCOUNT,
|
||||
} from "src/api/constants";
|
||||
import { toastError, useSelectState } from "src/store";
|
||||
import {
|
||||
Section,
|
||||
AccountFilter,
|
||||
@@ -30,6 +34,7 @@ const statusSelection = [
|
||||
];
|
||||
|
||||
export const RecentCalls = () => {
|
||||
const user = useSelectState("user");
|
||||
const [accounts] = useServiceProviderData<Account[]>("Accounts");
|
||||
const [accountSid, setAccountSid] = useState("");
|
||||
const [dateFilter, setDateFilter] = useState("today");
|
||||
@@ -86,7 +91,13 @@ export const RecentCalls = () => {
|
||||
<section className="filters filters--multi">
|
||||
<AccountFilter
|
||||
account={[accountSid, setAccountSid]}
|
||||
accounts={accounts}
|
||||
accounts={
|
||||
user?.scope === USER_ACCOUNT
|
||||
? accounts?.filter(
|
||||
(acct) => acct.account_sid === user.account_sid
|
||||
)
|
||||
: accounts
|
||||
}
|
||||
/>
|
||||
<SelectFilter
|
||||
id="date_filter"
|
||||
|
||||
@@ -121,7 +121,13 @@ export const SpeechServices = () => {
|
||||
<section className="filters filters--ender">
|
||||
<AccountFilter
|
||||
account={[accountSid, setAccountSid]}
|
||||
accounts={accounts}
|
||||
accounts={
|
||||
user?.scope === USER_ACCOUNT
|
||||
? accounts?.filter(
|
||||
(acct) => acct.account_sid === user.account_sid
|
||||
)
|
||||
: accounts
|
||||
}
|
||||
label="Used by"
|
||||
defaultOption
|
||||
/>
|
||||
|
||||
@@ -4,7 +4,11 @@ import { Link } from "react-router-dom";
|
||||
|
||||
import { useApiData, useServiceProviderData } from "src/api";
|
||||
import { ROUTE_INTERNAL_USERS } from "src/router/routes";
|
||||
import { USER_SCOPE_SELECTION, USER_ADMIN } from "src/api/constants";
|
||||
import {
|
||||
USER_SCOPE_SELECTION,
|
||||
USER_ADMIN,
|
||||
USER_ACCOUNT,
|
||||
} from "src/api/constants";
|
||||
|
||||
import {
|
||||
Section,
|
||||
@@ -20,6 +24,7 @@ import type { Account, User } from "src/api/types";
|
||||
import { useSelectState } from "src/store";
|
||||
|
||||
export const Users = () => {
|
||||
const user = useSelectState("user");
|
||||
const currentServiceProvider = useSelectState("currentServiceProvider");
|
||||
const [users] = useApiData<User[]>("Users");
|
||||
const [filter, setFilter] = useState("");
|
||||
@@ -82,8 +87,14 @@ export const Users = () => {
|
||||
/>
|
||||
<AccountFilter
|
||||
account={[accountSid, setAccountSid]}
|
||||
accounts={accounts}
|
||||
defaultOption={true}
|
||||
accounts={
|
||||
user?.scope === USER_ACCOUNT
|
||||
? accounts?.filter(
|
||||
(acct) => acct.account_sid === user.account_sid
|
||||
)
|
||||
: accounts
|
||||
}
|
||||
defaultOption
|
||||
/>
|
||||
</section>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user