@@ -3,6 +3,9 @@ import { createDispatchMap, select } from '@ngxs/store';
33import { TranslatePipe } from '@ngx-translate/core' ;
44
55import { Button } from 'primeng/button' ;
6+ import { Tooltip } from 'primeng/tooltip' ;
7+
8+ import { finalize } from 'rxjs' ;
69
710import {
811 ChangeDetectionStrategy ,
@@ -24,12 +27,17 @@ import { ToastService } from '@osf/shared/services/toast.service';
2427import { SocialModel } from '@shared/models/user/social.model' ;
2528import { SocialLinksForm } from '@shared/models/user/social-links.model' ;
2629
30+ import {
31+ AccountSettingsSelectors ,
32+ DeleteExternalIdentity ,
33+ GetExternalIdentities ,
34+ } from '../../../account-settings/store' ;
2735import { hasSocialLinkChanges , mapSocialLinkToPayload } from '../../helpers' ;
2836import { SocialFormComponent } from '../social-form/social-form.component' ;
2937
3038@Component ( {
3139 selector : 'osf-social' ,
32- imports : [ Button , ReactiveFormsModule , SocialFormComponent , TranslatePipe ] ,
40+ imports : [ Button , ReactiveFormsModule , SocialFormComponent , Tooltip , TranslatePipe ] ,
3341 templateUrl : './social.component.html' ,
3442 styleUrl : './social.component.scss' ,
3543 changeDetection : ChangeDetectionStrategy . OnPush ,
@@ -46,13 +54,21 @@ export class SocialComponent {
4654
4755 private readonly socials = SOCIAL_LINKS ;
4856
49- readonly actions = createDispatchMap ( { updateProfileSettingsSocialLinks : UpdateProfileSettingsSocialLinks } ) ;
57+ readonly actions = createDispatchMap ( {
58+ updateProfileSettingsSocialLinks : UpdateProfileSettingsSocialLinks ,
59+ deleteExternalIdentity : DeleteExternalIdentity ,
60+ getExternalIdentities : GetExternalIdentities ,
61+ } ) ;
5062 readonly socialLinks = select ( UserSelectors . getSocialLinks ) ;
63+ readonly externalIdentities = select ( AccountSettingsSelectors . getExternalIdentities ) ;
5164
5265 readonly socialLinksForm = this . fb . group ( { links : this . fb . array < SocialLinksForm > ( [ ] ) } ) ;
5366
5467 constructor ( ) {
55- effect ( ( ) => this . setInitialData ( ) ) ;
68+ effect ( ( ) => {
69+ this . setInitialData ( ) ;
70+ this . actions . getExternalIdentities ( ) ;
71+ } ) ;
5672 }
5773
5874 get links ( ) : FormArray < FormGroup > {
@@ -106,6 +122,30 @@ export class SocialComponent {
106122 return currentLinks . some ( ( link , index ) => hasSocialLinkChanges ( link , initialSocialLinks , index , this . socials ) ) ;
107123 }
108124
125+ get existingOrcid ( ) : string | undefined {
126+ const externalIdentities = this . externalIdentities ( ) ;
127+ const existingOrcid = externalIdentities ?. find ( ( identity ) => identity . id === 'ORCID' ) ;
128+ if ( existingOrcid && existingOrcid . status === 'VERIFIED' ) {
129+ return existingOrcid . externalId ;
130+ }
131+ return undefined ;
132+ }
133+
134+ disconnectOrcid ( ) : void {
135+ this . customConfirmationService . confirmDelete ( {
136+ headerKey : 'settings.accountSettings.connectedIdentities.deleteDialog.header' ,
137+ messageParams : { name : 'ORCID' } ,
138+ messageKey : 'settings.accountSettings.connectedIdentities.deleteDialog.message' ,
139+ onConfirm : ( ) => {
140+ this . loaderService . show ( ) ;
141+ this . actions
142+ . deleteExternalIdentity ( 'ORCID' )
143+ . pipe ( finalize ( ( ) => this . loaderService . hide ( ) ) )
144+ . subscribe ( ( ) => this . toastService . showSuccess ( 'settings.accountSettings.connectedIdentities.successDelete' ) ) ;
145+ } ,
146+ } ) ;
147+ }
148+
109149 private setInitialData ( ) : void {
110150 const socialLinks = this . socialLinks ( ) ;
111151 this . links . clear ( ) ;
0 commit comments