@ -276,7 +276,6 @@ import ImageMethodDialog from "../components/ImageMethodDialog.vue";
import QuickNav from "../components/QuickNav.vue" ;
import TopMessage from "../components/TopMessage.vue" ;
import { DEFAULT_IMAGE_API_SERVER , NotificationIface } from "../constants/app" ;
import * as databaseUtil from "../db/databaseUtil" ;
import { GenericCredWrapper , GiveActionClaim } from "../interfaces" ;
import {
createAndSubmitGive ,
@ -289,8 +288,20 @@ import {
import * as libsUtil from "../libs/util" ;
import { retrieveAccountDids } from "../libs/util" ;
import { logger } from "../utils/logger" ;
import { PlatformServiceFactory } from "@/services/PlatformServiceFactory" ;
import { Contact } from "@/db/tables/contacts" ;
import { PlatformServiceMixin } from "@/utils/PlatformServiceMixin" ;
import { createNotifyHelpers , TIMEOUTS } from "@/utils/notify" ;
import {
NOTIFY_GIFTED_DETAILS_RETRIEVAL_ERROR ,
NOTIFY_GIFTED_DETAILS_DELETE_IMAGE_CONFIRM ,
NOTIFY_GIFTED_DETAILS_DELETE_IMAGE_ERROR ,
NOTIFY_GIFTED_DETAILS_NO_IDENTIFIER ,
NOTIFY_GIFTED_DETAILS_PROJECT_PROVIDER_INFO ,
NOTIFY_GIFTED_DETAILS_BOTH_PROVIDER_SELECTED ,
NOTIFY_GIFTED_DETAILS_RECORDING_GIVE ,
NOTIFY_GIFTED_DETAILS_CREATE_GIVE_ERROR ,
NOTIFY_GIFTED_DETAILS_GIFT_RECORDED ,
} from "@/constants/notifications" ;
@ Component ( {
components : {
@ -298,11 +309,13 @@ import { Contact } from "@/db/tables/contacts";
QuickNav ,
TopMessage ,
} ,
mixins : [ PlatformServiceMixin ] ,
} )
export default class GiftedDetails extends Vue {
$notify ! : ( notification : NotificationIface , timeout ? : number ) => void ;
$route ! : RouteLocationNormalizedLoaded ;
$router ! : Router ;
$notify ! : ( notification : NotificationIface , timeout ? : number ) => void ;
notify ! : ReturnType < typeof createNotifyHelpers > ;
activeDid = "" ;
apiServer = "" ;
@ -332,6 +345,10 @@ export default class GiftedDetails extends Vue {
libsUtil = libsUtil ;
created ( ) {
this . notify = createNotifyHelpers ( this . $notify ) ;
}
async mounted ( ) {
try {
this . prevCredToEdit = ( this . $route . query [ "prevCredToEdit" ] as string )
@ -340,14 +357,9 @@ export default class GiftedDetails extends Vue {
) as GenericCredWrapper < GiveActionClaim > )
: undefined ;
} catch ( error ) {
this . $notify (
{
group : "alert" ,
type : "danger" ,
title : "Retrieval Error" ,
text : "The previous record isn't available for editing. If you submit, you'll create a new record." ,
} ,
6000 ,
this . notify . error (
NOTIFY_GIFTED_DETAILS_RETRIEVAL_ERROR . message ,
TIMEOUTS . LONG ,
) ;
}
@ -437,7 +449,7 @@ export default class GiftedDetails extends Vue {
this . imageUrl = this . $route . query [ "shareUrl" ] as string ;
}
const settings = await databaseUtil . retrieveSettingsForActiveAccount ( ) ;
const settings = await this . $accountSettings ( ) ;
this . apiServer = settings . apiServer || "" ;
this . activeDid = settings . activeDid || "" ;
@ -445,11 +457,8 @@ export default class GiftedDetails extends Vue {
( this . giverDid && ! this . giverName ) ||
( this . recipientDid && ! this . recipientName )
) {
const platformService = PlatformServiceFactory . getInstance ( ) ;
const dbContacts = await platformService . dbQuery (
"SELECT * FROM contacts" ,
) ;
const allContacts = databaseUtil . mapQueryResultToValues (
const dbContacts = await this . $dbQuery ( "SELECT * FROM contacts" ) ;
const allContacts = this . $mapQueryResultToValues (
dbContacts ,
) as unknown as Contact [ ] ;
const allMyDids = await retrieveAccountDids ( ) ;
@ -544,15 +553,10 @@ export default class GiftedDetails extends Vue {
}
confirmDeleteImage ( ) {
this . $notify (
{
group : "modal" ,
type : "confirm" ,
title : "Are you sure you want to delete the image?" ,
text : "" ,
onYes : this . deleteImage ,
} ,
- 1 ,
this . notify . confirm (
NOTIFY_GIFTED_DETAILS_DELETE_IMAGE_CONFIRM . message ,
this . deleteImage ,
TIMEOUTS . LONG ,
) ;
}
@ -581,16 +585,10 @@ export default class GiftedDetails extends Vue {
/ / ( e i t h e r t h e y ' l l s i m p l y c o n t i n u e o r t h e y ' r e c a n c e l i n g a n d g o i n g b a c k )
} else {
logger . error ( "Problem deleting image:" , response ) ;
this . $notify (
{
group : "alert" ,
type : "danger" ,
title : "Error" ,
text : "There was a problem deleting the image." ,
} ,
5000 ,
this . notify . error (
NOTIFY_GIFTED_DETAILS_DELETE_IMAGE_ERROR . message ,
TIMEOUTS . LONG ,
) ;
/ / k e e p t h e i m a g e U r l i n l o c a l S t o r a g e s o t h e u s e r c a n t r y a g a i n i f t h e y w a n t
return ;
}
@ -598,76 +596,39 @@ export default class GiftedDetails extends Vue {
this . imageUrl = "" ;
} catch ( error ) {
logger . error ( "Error deleting image:" , error ) ;
/ / e s l i n t - d i s a b l e - n e x t - l i n e @ t y p e s c r i p t - e s l i n t / n o - e x p l i c i t - a n y
if ( ( error as any ) . response . status === 404 ) {
logger . log ( "Weird: the image was already deleted." , error ) ;
localStorage . removeItem ( "imageUrl" ) ;
this . imageUrl = "" ;
/ / i t a l r e a d y d o e s n ' t e x i s t s o w e w o n ' t s a y a n y t h i n g t o t h e u s e r
} else {
this . $notify (
{
group : "alert" ,
type : "danger" ,
title : "Error" ,
text : "There was an error deleting the image." ,
} ,
5000 ,
this . notify . error (
NOTIFY_GIFTED_DETAILS_DELETE_IMAGE_ERROR . message ,
TIMEOUTS . LONG ,
) ;
}
}
}
async confirm ( ) {
if ( ! this . activeDid ) {
this . $notify (
{
group : "alert" ,
type : "danger" ,
title : "Error" ,
text : "You must select an identifier before you can record a give." ,
} ,
2000 ,
this . notify . error (
NOTIFY_GIFTED_DETAILS_NO_IDENTIFIER . message ,
TIMEOUTS . SHORT ,
) ;
return ;
}
if ( parseFloat ( this . amountInput ) < 0 ) {
this . $notify (
{
group : "alert" ,
type : "danger" ,
text : "You may not send a negative number." ,
title : "" ,
} ,
2000 ,
this . notify . error (
NOTIFY_GIFTED_DETAILS_NO_IDENTIFIER . message ,
TIMEOUTS . SHORT ,
) ;
return ;
}
if ( ! this . description && ! parseFloat ( this . amountInput ) ) {
this . $notify (
{
group : "alert" ,
type : "danger" ,
title : "Error" ,
text : ` You must enter a description or some number of ${
this . libsUtil . UNIT_LONG [ this . unitCode ]
} . ` ,
} ,
2000 ,
this . notify . error (
NOTIFY_GIFTED_DETAILS_NO_IDENTIFIER . message ,
TIMEOUTS . SHORT ,
) ;
return ;
}
this . $notify (
{
group : "alert" ,
type : "toast" ,
text : "Recording the give..." ,
title : "" ,
} ,
1000 ,
this . notify . toast (
NOTIFY_GIFTED_DETAILS_RECORDING_GIVE . message ,
TIMEOUTS . SHORT ,
) ;
/ / t h i s i s a s y n c h r o n o u s , b u t w e d o n ' t n e e d t o w a i t f o r i t t o c o m p l e t e
@ -676,49 +637,29 @@ export default class GiftedDetails extends Vue {
notifyUserOfGiver ( ) {
if ( ! this . giverDid ) {
this . $notify (
{
group : "alert" ,
type : "warning" ,
title : "Go To The Contacts Page" ,
text : "To assign a giver, you must open this page from a contact." ,
} ,
3000 ,
this . notify . warning (
NOTIFY_GIFTED_DETAILS_NO_IDENTIFIER . message ,
TIMEOUTS . SHORT ,
) ;
} else {
this . $notify (
{
group : "alert" ,
type : "warning" ,
title : "Unavailable" ,
text : "You cannot assign both a giver and a project." ,
} ,
3000 ,
this . notify . warning (
NOTIFY_GIFTED_DETAILS_BOTH_PROVIDER_SELECTED . message ,
TIMEOUTS . SHORT ,
) ;
}
}
notifyUserOfRecipient ( ) {
if ( ! this . recipientDid ) {
this . $notify (
{
group : "alert" ,
type : "warning" ,
title : "Go To The Contacts Page" ,
text : "To assign to a recipient, you must open this page from a contact." ,
} ,
3000 ,
this . notify . warning (
NOTIFY_GIFTED_DETAILS_NO_IDENTIFIER . message ,
TIMEOUTS . SHORT ,
) ;
} else {
/ / m u s t b e b e c a u s e g i v e n T o P r o j e c t i s t r u e
this . $notify (
{
group : "alert" ,
type : "warning" ,
title : "Unavailable" ,
text : "You cannot assign both to a recipient and to a project." ,
} ,
3000 ,
this . notify . warning (
NOTIFY_GIFTED_DETAILS_BOTH_PROVIDER_SELECTED . message ,
TIMEOUTS . SHORT ,
) ;
}
}
@ -726,25 +667,15 @@ export default class GiftedDetails extends Vue {
notifyUserOfProvidingProject ( ) {
/ / w e ' r e h e r e b e c a u s e t h e y c l i c k e d a n d e i t h e r t h e r e i s n o p r o v i d e r p r o j e c t o r t h e r e i s a g i v e r c h o s e n
if ( ! this . providerProjectId ) {
this . $notify (
{
group : "alert" ,
type : "warning" ,
title : "Go To The Project Page" ,
text : "To select a project as a provider, you must open this page through a project." ,
} ,
3000 ,
this . notify . warning (
NOTIFY_GIFTED_DETAILS_PROJECT_PROVIDER_INFO . message ,
TIMEOUTS . SHORT ,
) ;
} else {
/ / n o p r o v i d i n g p r o j e c t w a s c h o s e n
this . $notify (
{
group : "alert" ,
type : "warning" ,
title : "Unavailable" ,
text : "You cannot select both a giving project and person." ,
} ,
3000 ,
this . notify . warning (
NOTIFY_GIFTED_DETAILS_BOTH_PROVIDER_SELECTED . message ,
TIMEOUTS . SHORT ,
) ;
}
}
@ -752,25 +683,15 @@ export default class GiftedDetails extends Vue {
notifyUserFulfillsProject ( ) {
/ / w e ' r e h e r e b e c a u s e t h e y c l i c k e d a n d e i t h e r t h e r e i s n o f u l f i l l s p r o j e c t o r t h e r e i s a r e c i p i e n t c h o s e n
if ( ! this . fulfillsProjectId ) {
this . $notify (
{
group : "alert" ,
type : "warning" ,
title : "Go To The Project Page" ,
text : "To assign to a project, you must open this page through a project." ,
} ,
3000 ,
this . notify . warning (
NOTIFY_GIFTED_DETAILS_PROJECT_PROVIDER_INFO . message ,
TIMEOUTS . SHORT ,
) ;
} else {
/ / n o f u l f i l l s p r o j e c t w a s c h o s e n
this . $notify (
{
group : "alert" ,
type : "warning" ,
title : "Unavailable" ,
text : "You cannot assign both to a project and to a recipient." ,
} ,
3000 ,
this . notify . warning (
NOTIFY_GIFTED_DETAILS_BOTH_PROVIDER_SELECTED . message ,
TIMEOUTS . SHORT ,
) ;
}
}
@ -831,24 +752,14 @@ export default class GiftedDetails extends Vue {
if ( ! result . success ) {
const errorMessage = result . error ;
logger . error ( "Error with give creation result:" , result ) ;
this . $notify (
{
group : "alert" ,
type : "danger" ,
title : "Error" ,
text : errorMessage || "There was an error creating the give." ,
} ,
5000 ,
this . notify . error (
errorMessage || NOTIFY_GIFTED_DETAILS_CREATE_GIVE_ERROR . message ,
TIMEOUTS . LONG ,
) ;
} else {
this . $notify (
{
group : "alert" ,
type : "success" ,
title : "Success" ,
text : ` That gift was recorded. ` ,
} ,
3000 ,
this . notify . success (
NOTIFY_GIFTED_DETAILS_GIFT_RECORDED . message ,
TIMEOUTS . SHORT ,
) ;
localStorage . removeItem ( "imageUrl" ) ;
if ( this . destinationPathAfter ) {
@ -864,15 +775,7 @@ export default class GiftedDetails extends Vue {
error . userMessage ||
error . response ? . data ? . error ? . message ||
"There was an error recording the give." ;
this . $notify (
{
group : "alert" ,
type : "danger" ,
title : "Error" ,
text : errorMessage ,
} ,
5000 ,
) ;
this . notify . error ( errorMessage , TIMEOUTS . LONG ) ;
}
}
@ -903,15 +806,7 @@ export default class GiftedDetails extends Vue {
/ / H e l p e r f u n c t i o n s f o r r e a d a b i l i t y
explainData ( ) {
this . $notify (
{
group : "alert" ,
type : "success" ,
title : "Data Sharing" ,
text : libsUtil . PRIVACY_MESSAGE ,
} ,
7000 ,
) ;
this . notify . success ( libsUtil . PRIVACY_MESSAGE , TIMEOUTS . LONG ) ;
}
/ / C o m p u t e d p r o p e r t y t o g e t u n i t o p t i o n s