mirror of
https://github.com/jambonz/jambonz-webapp.git
synced 2025-12-19 05:37:43 +00:00
refined method for applications index
This commit is contained in:
@@ -36,7 +36,6 @@ import type {
|
|||||||
Alert,
|
Alert,
|
||||||
PagedResponse,
|
PagedResponse,
|
||||||
RecentCall,
|
RecentCall,
|
||||||
Application,
|
|
||||||
} from "./types";
|
} from "./types";
|
||||||
|
|
||||||
/** Wrap all requests to normalize response handling */
|
/** Wrap all requests to normalize response handling */
|
||||||
@@ -283,10 +282,6 @@ export const getAccountWebhook = (sid: string) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getApplications = (sid: string) => {
|
|
||||||
return getFetch<Application[]>(`${API_ACCOUNTS}/${sid}/Applications`);
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Wrappers for APIs that can have a mock dev server response */
|
/** Wrappers for APIs that can have a mock dev server response */
|
||||||
|
|
||||||
export const getRecentCalls = (sid: string) => {
|
export const getRecentCalls = (sid: string) => {
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ import React, { useEffect, useState } from "react";
|
|||||||
import { H1, Button, Icon } from "jambonz-ui";
|
import { H1, Button, Icon } from "jambonz-ui";
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
|
|
||||||
import { deleteApplication, getApplications, getFetch } from "src/api";
|
import { deleteApplication, getFetch } from "src/api";
|
||||||
import { API_APPLICATIONS } from "src/api/constants";
|
import { API_ACCOUNTS } from "src/api/constants";
|
||||||
import { ROUTE_INTERNAL_APPLICATIONS } from "src/router/routes";
|
import { ROUTE_INTERNAL_APPLICATIONS } from "src/router/routes";
|
||||||
import { Icons, Section, Spinner, AccountFilter } from "src/components";
|
import { Icons, Section, Spinner, AccountFilter } from "src/components";
|
||||||
import { DeleteApplication } from "./delete";
|
import { DeleteApplication } from "./delete";
|
||||||
@@ -16,13 +16,11 @@ export const Applications = () => {
|
|||||||
const [applications, setApplications] = useState<Application[] | null>(null);
|
const [applications, setApplications] = useState<Application[] | null>(null);
|
||||||
const [application, setApplication] = useState<Application | null>(null);
|
const [application, setApplication] = useState<Application | null>(null);
|
||||||
|
|
||||||
const [refetch, setRefetch] = useState(0);
|
|
||||||
|
|
||||||
const handleDelete = () => {
|
const handleDelete = () => {
|
||||||
if (application) {
|
if (application) {
|
||||||
deleteApplication(application.application_sid)
|
deleteApplication(application.application_sid)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
setRefetch(refetch + 1);
|
getApplications();
|
||||||
setApplication(null);
|
setApplication(null);
|
||||||
toastSuccess(
|
toastSuccess(
|
||||||
<>
|
<>
|
||||||
@@ -36,22 +34,19 @@ export const Applications = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getApplications = () => {
|
||||||
|
getFetch<Application[]>(`${API_ACCOUNTS}/${accountSid}/Applications`)
|
||||||
|
.then(({ json }) => setApplications(json))
|
||||||
|
.catch((error) => {
|
||||||
|
toastError(error.msg);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (accountSid) {
|
if (accountSid) {
|
||||||
getApplications(accountSid)
|
getApplications();
|
||||||
.then(({ json }) => setApplications(json))
|
|
||||||
.catch((error) => {
|
|
||||||
toastError(error.msg);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
// accountSid is null is "All accounts"
|
|
||||||
getFetch<Application[]>(API_APPLICATIONS)
|
|
||||||
.then(({ json }) => setApplications(json))
|
|
||||||
.catch((error) => {
|
|
||||||
toastError(error.msg);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}, [accountSid, refetch]);
|
}, [accountSid]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -67,11 +62,7 @@ export const Applications = () => {
|
|||||||
</Link>
|
</Link>
|
||||||
</section>
|
</section>
|
||||||
<section className="filters">
|
<section className="filters">
|
||||||
<AccountFilter
|
<AccountFilter account={[accountSid, setAccountSid]} />
|
||||||
label="Used by"
|
|
||||||
account={[accountSid, setAccountSid]}
|
|
||||||
defaultOption
|
|
||||||
/>
|
|
||||||
</section>
|
</section>
|
||||||
<Section
|
<Section
|
||||||
{...(applications && applications.length > 0 ? { slim: true } : {})}
|
{...(applications && applications.length > 0 ? { slim: true } : {})}
|
||||||
|
|||||||
Reference in New Issue
Block a user