Commit f8e26066 authored by Max Alekseenko's avatar Max Alekseenko

create a new app record if one does not exist

parent a5e56e37
...@@ -90,16 +90,24 @@ export default function useRatings() { ...@@ -90,16 +90,24 @@ export default function useRatings() {
}, [ address, addressCountersQuery ]); }, [ address, addressCountersQuery ]);
const rateApp = useCallback(async(appId: string, recordId: string | undefined, rating: number) => { const rateApp = useCallback(async(appId: string, recordId: string | undefined, rating: number) => {
if (!address || !base || !recordId) {
return;
}
setIsSending(true); setIsSending(true);
try { try {
if (!address || !base) {
throw new Error('Address is missing');
}
let appRecordId = recordId;
if (!appRecordId) {
const records = await base('apps_ratings').create([ { fields: { appId } } ]);
appRecordId = records[0].id;
if (!appRecordId) {
throw new Error('Record ID is missing');
}
}
await base('users_ratings').create([ await base('users_ratings').create([
{ {
fields: { fields: {
address, address,
appRecordId: [ recordId ], appRecordId: [ appRecordId ],
rating, rating,
}, },
}, },
...@@ -111,7 +119,13 @@ export default function useRatings() { ...@@ -111,7 +119,13 @@ export default function useRatings() {
description: 'Your rating improves the service', description: 'Your rating improves the service',
}); });
fetchRatings(); fetchRatings();
} catch (error) {} } catch (error) {
toast({
status: 'error',
title: 'Ooops! Something went wrong',
description: 'Please try again later',
});
}
setIsSending(false); setIsSending(false);
}, [ address, userRatings, fetchRatings, toast ]); }, [ address, userRatings, fetchRatings, toast ]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment