@@ -5,7 +5,7 @@ import { isEqual as _isEqual } from 'lodash-es';
5
5
import { ActivatedRoute , Router } from '@angular/router' ;
6
6
7
7
import { LineageModelGeneratorService } from '@mm-services/lineage-model-generator.service' ;
8
- import { FormService } from '@mm-services/form.service' ;
8
+ import { FormService , DuplicatesFoundError , Duplicate } from '@mm-services/form.service' ;
9
9
import { EnketoFormContext } from '@mm-services/enketo.service' ;
10
10
import { ContactTypesService } from '@mm-services/contact-types.service' ;
11
11
import { DbService } from '@mm-services/db.service' ;
@@ -55,6 +55,18 @@ export class ContactsEditComponent implements OnInit, OnDestroy, AfterViewInit {
55
55
private trackSave ;
56
56
private trackMetadata = { action : '' , form : '' } ;
57
57
58
+ private duplicateCheck ;
59
+ acknowledged = false ;
60
+ onAcknowledgeChange ( value : boolean ) {
61
+ this . acknowledged = value ;
62
+ }
63
+
64
+ onNavigateToDuplicate ( _id : string ) {
65
+ this . router . navigate ( [ '/contacts' , _id , 'edit' ] ) ;
66
+ }
67
+
68
+ duplicates : Duplicate [ ] = [ ] ;
69
+
58
70
ngOnInit ( ) {
59
71
this . trackRender = this . performanceService . track ( ) ;
60
72
this . subscribeToStore ( ) ;
@@ -153,6 +165,10 @@ export class ContactsEditComponent implements OnInit, OnDestroy, AfterViewInit {
153
165
this . contentError = false ;
154
166
this . errorTranslationKey = false ;
155
167
168
+ // Reset when when navigated to duplicate
169
+ this . duplicates = [ ] ;
170
+ this . acknowledged = false ;
171
+
156
172
try {
157
173
const contact = await this . getContact ( ) ;
158
174
const contactTypeId = this . contactTypesService . getTypeId ( contact ) || this . routeSnapshot . params ?. type ;
@@ -272,6 +288,7 @@ export class ContactsEditComponent implements OnInit, OnDestroy, AfterViewInit {
272
288
private async renderForm ( formId : string , titleKey : string ) {
273
289
const formDoc = await this . dbService . get ( ) . get ( formId ) ;
274
290
this . xmlVersion = formDoc . xmlVersion ;
291
+ this . duplicateCheck = formDoc . context ?. duplicate_check ;
275
292
276
293
this . globalActions . setEnketoEditedStatus ( false ) ;
277
294
@@ -326,7 +343,7 @@ export class ContactsEditComponent implements OnInit, OnDestroy, AfterViewInit {
326
343
$ ( 'form.or' ) . trigger ( 'beforesave' ) ;
327
344
328
345
return this . formService
329
- . saveContact ( form , docId , this . enketoContact . type , this . xmlVersion )
346
+ . saveContact ( form , docId , this . enketoContact . type , this . xmlVersion , this . duplicateCheck , this . acknowledged )
330
347
. then ( ( result ) => {
331
348
console . debug ( 'saved contact' , result ) ;
332
349
@@ -345,6 +362,11 @@ export class ContactsEditComponent implements OnInit, OnDestroy, AfterViewInit {
345
362
this . router . navigate ( [ '/contacts' , result . docId ] ) ;
346
363
} )
347
364
. catch ( ( err ) => {
365
+ if ( err instanceof DuplicatesFoundError ) {
366
+ this . duplicates = err . duplicates ;
367
+ err = Error ( err . message ) ;
368
+ }
369
+
348
370
console . error ( 'Error submitting form data' , err ) ;
349
371
350
372
this . globalActions . setEnketoSavingStatus ( false ) ;
0 commit comments