@@ -10,6 +10,7 @@ import {
1010 i18n ,
1111 notifyError ,
1212 notifySuccess ,
13+ SettingsService ,
1314 User ,
1415} from '@placeos/common' ;
1516import { IconComponent , TranslatePipe } from '@placeos/components' ;
@@ -128,6 +129,7 @@ import { VisitorFlowSuccessComponent } from './visitor-flow-success.component';
128129} )
129130export class VisitorFlowNewComponent extends AsyncHandler implements OnInit {
130131 private _booking_form = inject ( BookingFormService ) ;
132+ private _settings = inject ( SettingsService ) ;
131133 private _router = inject ( Router ) ;
132134 private _route = inject ( ActivatedRoute ) ;
133135 private _existing_siblings : Booking [ ] = [ ] ;
@@ -223,6 +225,7 @@ export class VisitorFlowNewComponent extends AsyncHandler implements OnInit {
223225 this . _booking_form . last_count = is_multiple
224226 ? this . form_value ( ) ?. assets ?. length || 1
225227 : 1 ;
228+ this . _saveRecentVisitors ( is_multiple ) ;
226229 await ( is_multiple ? this . _bookForMany ( ) : this . _bookForOne ( ) ) ;
227230 const name = is_multiple ? i18n ( 'BOOKINGS.VISITORS' ) : asset_name ;
228231 notifySuccess (
@@ -245,6 +248,35 @@ export class VisitorFlowNewComponent extends AsyncHandler implements OnInit {
245248 }
246249 }
247250
251+ private _saveRecentVisitors ( is_multiple : boolean ) {
252+ const old_visitors : string [ ] =
253+ this . _settings . get ( 'visitor-invitees' ) || [ ] ;
254+ const value = this . _booking_form . form . getRawValue ( ) ;
255+ const toEntry = ( email : string , name = '' , org = '' ) =>
256+ `${ email } |${ name } |${ org } ` ;
257+ if ( is_multiple && value . assets ?. length ) {
258+ const emails = new Set (
259+ value . assets . map ( ( a ) => a . email ) . filter ( Boolean ) ,
260+ ) ;
261+ this . _settings . saveUserSetting ( 'visitor-invitees' , [
262+ ...old_visitors . filter (
263+ ( v ) => ! emails . has ( `${ v } ` . split ( '|' ) [ 0 ] ) ,
264+ ) ,
265+ ...value . assets
266+ . filter ( ( a ) => ! ! a . email )
267+ . map ( ( a ) => toEntry ( a . email , a . name , a . organisation ) ) ,
268+ ] ) ;
269+ } else {
270+ const { asset_id, asset_name, company } = value ;
271+ this . _settings . saveUserSetting ( 'visitor-invitees' , [
272+ ...old_visitors . filter (
273+ ( v ) => `${ v } ` . split ( '|' ) [ 0 ] !== asset_id ,
274+ ) ,
275+ toEntry ( asset_id , asset_name , company ) ,
276+ ] ) ;
277+ }
278+ }
279+
248280 private async _bookForOne ( ) {
249281 const value = this . _booking_form . form . value ;
250282 this . _booking_form . form . patchValue ( {
0 commit comments