mirror of
https://github.com/jambonz/jambonz-webapp.git
synced 2026-07-04 19:21:58 +00:00
Prefill predefined carrier gateways in a form (#147)
* add gateways api call to hook * add route to carrier template * apply review comments * omit request.body if no payload is provided * remove ternary where not needed * fix typing of payload * fix payload type to allow undefined Co-authored-by: eglehelms <e.helms@cognigy.com>
This commit is contained in:
+14
-2
@@ -194,10 +194,13 @@ export const getFetch = <Type>(url: string) => {
|
||||
});
|
||||
};
|
||||
|
||||
export const postFetch = <Type, Payload>(url: string, payload: Payload) => {
|
||||
export const postFetch = <Type, Payload = undefined>(
|
||||
url: string,
|
||||
payload?: Payload
|
||||
) => {
|
||||
return fetchTransport<Type>(url, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(payload),
|
||||
...(payload && { body: JSON.stringify(payload) }),
|
||||
headers: getAuthHeaders(),
|
||||
});
|
||||
};
|
||||
@@ -284,6 +287,15 @@ export const postCarrier = (sid: string, payload: Partial<Carrier>) => {
|
||||
);
|
||||
};
|
||||
|
||||
export const postPredefinedCarrierTemplate = (
|
||||
currentServiceProviderSid: string,
|
||||
predefinedCarrierSid: string
|
||||
) => {
|
||||
return postFetch<SidResponse>(
|
||||
`${API_BASE_URL}/ServiceProviders/${currentServiceProviderSid}/PredefinedCarriers/${predefinedCarrierSid}`
|
||||
);
|
||||
};
|
||||
|
||||
export const postSipGateway = (payload: Partial<SipGateway>) => {
|
||||
return postFetch<SidResponse, Partial<SipGateway>>(API_SIP_GATEWAY, payload);
|
||||
};
|
||||
|
||||
@@ -299,6 +299,7 @@ export interface Carrier {
|
||||
|
||||
export interface PredefinedCarrier extends Carrier {
|
||||
requires_static_ip: boolean;
|
||||
predefined_carrier_sid: string;
|
||||
}
|
||||
|
||||
export interface Gateway {
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
putSmppGateway,
|
||||
useApiData,
|
||||
useServiceProviderData,
|
||||
postPredefinedCarrierTemplate,
|
||||
} from "src/api";
|
||||
import {
|
||||
DEFAULT_SIP_GATEWAY,
|
||||
@@ -523,9 +524,22 @@ export const CarrierForm = ({
|
||||
|
||||
useEffect(() => {
|
||||
if (predefinedName && hasLength(predefinedCarriers)) {
|
||||
setCarrierStates(
|
||||
predefinedCarriers.filter((a) => a.name === predefinedName)[0]
|
||||
);
|
||||
const predefinedCarrierSid = predefinedCarriers.find(
|
||||
(a) => a.name === predefinedName
|
||||
)?.predefined_carrier_sid;
|
||||
|
||||
if (currentServiceProvider && predefinedCarrierSid) {
|
||||
postPredefinedCarrierTemplate(
|
||||
currentServiceProvider.service_provider_sid,
|
||||
predefinedCarrierSid
|
||||
)
|
||||
.then(({ json }) => {
|
||||
navigate(`${ROUTE_INTERNAL_CARRIERS}/${json.sid}/edit`);
|
||||
})
|
||||
.catch((error) => {
|
||||
toastError(error.msg);
|
||||
});
|
||||
}
|
||||
}
|
||||
}, [predefinedName]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user