mirror of
https://github.com/OneUptime/oneuptime
synced 2024-11-21 22:59:07 +00:00
make manual recharge work
This commit is contained in:
parent
ded0e2638b
commit
e3c613c1a1
@ -12,6 +12,7 @@ import ObjectID from 'Common/Types/ObjectID';
|
||||
import JSONFunctions from 'Common/Types/JSONFunctions';
|
||||
import Permission, { UserPermission } from 'Common/Types/Permission';
|
||||
import Exception from 'Common/Types/Exception/Exception';
|
||||
import PositiveNumber from 'Common/Types/PositiveNumber';
|
||||
|
||||
const router: ExpressRouter = Express.getRouter();
|
||||
|
||||
@ -20,7 +21,19 @@ router.post(
|
||||
UserMiddleware.getUserMiddleware,
|
||||
async (req: ExpressRequest, res: ExpressResponse) => {
|
||||
try {
|
||||
const amount: number = req.body.amount;
|
||||
let amount: number | PositiveNumber =
|
||||
JSONFunctions.deserializeValue(req.body.amount) as
|
||||
| number
|
||||
| PositiveNumber;
|
||||
|
||||
if (amount instanceof PositiveNumber) {
|
||||
amount = amount.toNumber();
|
||||
}
|
||||
|
||||
if (typeof amount === 'string') {
|
||||
amount = parseInt(amount);
|
||||
}
|
||||
|
||||
const projectId: ObjectID = JSONFunctions.deserializeValue(
|
||||
req.body.projectId
|
||||
) as ObjectID;
|
||||
@ -97,6 +110,8 @@ router.post(
|
||||
} catch (err: any) {
|
||||
return Response.sendErrorResponse(req, res, err as Exception);
|
||||
}
|
||||
|
||||
return Response.sendEmptyResponse(req, res);
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -17,6 +17,8 @@ import { JSONObject } from 'Common/Types/JSON';
|
||||
import API from 'CommonUI/src/Utils/API/API';
|
||||
import URL from 'Common/Types/API/URL';
|
||||
import Navigation from 'CommonUI/src/Utils/Navigation';
|
||||
import HTTPResponse from 'Common/Types/API/HTTPResponse';
|
||||
import HTTPErrorResponse from 'Common/Types/API/HTTPErrorResponse';
|
||||
|
||||
const Settings: FunctionComponent<PageComponentProps> = (
|
||||
_props: PageComponentProps
|
||||
@ -69,6 +71,8 @@ const Settings: FunctionComponent<PageComponentProps> = (
|
||||
icon: IconProp.Add,
|
||||
onClick: () => {
|
||||
setShowRechargeBalanceModal(true);
|
||||
setRechargeBalanceError(null);
|
||||
setIsRechargeBalanceLoading(false);
|
||||
},
|
||||
},
|
||||
],
|
||||
@ -336,7 +340,9 @@ const Settings: FunctionComponent<PageComponentProps> = (
|
||||
onSubmit={async (item: JSONObject) => {
|
||||
setIsRechargeBalanceLoading(true);
|
||||
try {
|
||||
await API.post(
|
||||
const response:
|
||||
| HTTPResponse<JSONObject>
|
||||
| HTTPErrorResponse = await API.post(
|
||||
URL.fromString(
|
||||
DASHBOARD_API_URL.toString()
|
||||
).addRoute('/notification/recharge'),
|
||||
@ -346,9 +352,17 @@ const Settings: FunctionComponent<PageComponentProps> = (
|
||||
DashboardNavigation.getProjectId()?.toString(),
|
||||
}
|
||||
);
|
||||
|
||||
if (response.isFailure()) {
|
||||
setRechargeBalanceError(
|
||||
API.getFriendlyMessage(response)
|
||||
);
|
||||
setIsRechargeBalanceLoading(false);
|
||||
} else {
|
||||
setIsRechargeBalanceLoading(false);
|
||||
setShowRechargeBalanceModal(false);
|
||||
Navigation.reload();
|
||||
}
|
||||
} catch (e) {
|
||||
setRechargeBalanceError(API.getFriendlyMessage(e));
|
||||
setIsRechargeBalanceLoading(false);
|
||||
@ -369,7 +383,7 @@ const Settings: FunctionComponent<PageComponentProps> = (
|
||||
minValue: 20,
|
||||
maxValue: 1000,
|
||||
},
|
||||
fieldType: FormFieldSchemaType.PositveNumber,
|
||||
fieldType: FormFieldSchemaType.Number,
|
||||
},
|
||||
],
|
||||
}}
|
||||
|
Loading…
Reference in New Issue
Block a user