mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 06:28:51 +00:00
refactor(server/marketplace): Refactor to use promise events
This commit is contained in:
1 parent
4afa9c691b
commit
3df2f88759
9 files changed
+160
-134
No files matched your search
@@ -51,21 +51,21 @@ export const ListingActions: React.FC<MarketplaceListing> = ({ children, ...list
|
||||
};
|
||||
|
||||
const handleReportListing = () => {
|
||||
fetchNui<MarketplaceActionResp>(MarketplaceEvents.DELETE_LISTING, listing).then(
|
||||
({ err, errMsg }) => {
|
||||
if (err) {
|
||||
return addAlert({
|
||||
message: t(errMsg),
|
||||
type: 'error',
|
||||
});
|
||||
}
|
||||
|
||||
addAlert({
|
||||
message: t('APPS_MARKETPLACE_REPORT_LISTING_SUCCESS'),
|
||||
type: 'success',
|
||||
fetchNui<MarketplaceActionResp>(MarketplaceEvents.REPORT_LISTING, {
|
||||
listingId: listing.id,
|
||||
}).then(({ err, errMsg }) => {
|
||||
if (err) {
|
||||
return addAlert({
|
||||
message: t(errMsg),
|
||||
type: 'error',
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
addAlert({
|
||||
message: t('APPS_MARKETPLACE_REPORT_LISTING_SUCCESS'),
|
||||
type: 'success',
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const handleCall = () => {
|
||||
|
||||
@@ -56,7 +56,7 @@ export const ListingForm = () => {
|
||||
}).then(({ err, errMsg }) => {
|
||||
if (err) {
|
||||
return addAlert({
|
||||
message: t(errMsg),
|
||||
message: t('errMsg'),
|
||||
type: 'error',
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import { atom, selector, useRecoilValue, useSetRecoilState } from 'recoil';
|
||||
import { MarketplaceEvents, MarketplaceListing } from '../../../../../typings/marketplace';
|
||||
import {
|
||||
MarketplaceEvents,
|
||||
MarketplaceFetchResp,
|
||||
MarketplaceListing,
|
||||
} from '../../../../../typings/marketplace';
|
||||
import { fetchNui } from '../../../utils/fetchNui';
|
||||
|
||||
const defaultData: MarketplaceListing[] = [
|
||||
@@ -30,7 +34,7 @@ const listingState = atom<MarketplaceListing[]>({
|
||||
key: 'defaultListings',
|
||||
get: async () => {
|
||||
try {
|
||||
return await fetchNui<MarketplaceListing[]>(MarketplaceEvents.FETCH_LISTING);
|
||||
return (await fetchNui<MarketplaceFetchResp>(MarketplaceEvents.FETCH_LISTING)).data;
|
||||
} catch (e) {
|
||||
if (process.env.NODE_ENV === 'development' && !process.env.REACT_APP_IN_GAME) {
|
||||
return defaultData;
|
||||
|
||||
@@ -23,7 +23,6 @@ export const useMarketplaceService = () => {
|
||||
const deleteDTO = listing as MarketplaceDeleteDTO;
|
||||
return setListings((currVal) => {
|
||||
const arrayPos = currVal.map((item) => item.id).indexOf(deleteDTO.id);
|
||||
|
||||
return [...currVal].splice(arrayPos);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user