@@ -4,7 +4,12 @@ import { addScriptBreadcrumb, ClientScriptError } from '@components/scripts/erro
44import { handleScriptError } from '@components/scripts/errors/handler'
55import { defineCustomElement } from '@components/scripts/utils'
66import type { WebComponentModule } from '@components/scripts/@types/webComponentModule'
7- import { getPrivacyFormElements } from './selectors'
7+ import {
8+ getPrivacyFormElements ,
9+ getPrivacyPreviewToastElement ,
10+ getPrivacyPreviewToastElements ,
11+ getPrivacySubmitButton ,
12+ } from './selectors'
813
914type MessageType = 'success' | 'error' | 'info'
1015type RequestType = 'ACCESS' | 'DELETE'
@@ -70,10 +75,7 @@ export class PrivacyFormElement extends LitElement {
7075 private deleteMessage ! : HTMLElement
7176
7277 private getPreviewToastElements ( requestType : RequestType ) : HTMLElement [ ] {
73- const prefix = requestType === 'ACCESS' ? 'access' : 'delete'
74- return [ 'success' , 'loading' , 'error' , 'validation' ]
75- . map ( state => this . querySelector < HTMLElement > ( `#${ prefix } -preview-toast-${ state } ` ) )
76- . filter ( ( el ) : el is HTMLElement => el !== null )
78+ return getPrivacyPreviewToastElements ( requestType , this )
7779 }
7880
7981 override connectedCallback ( ) : void {
@@ -160,7 +162,7 @@ export class PrivacyFormElement extends LitElement {
160162 state : RequestPreviewState | 'idle' ,
161163 requestType ?: RequestType
162164 ) : void {
163- form . dataset . privacyState = state
165+ form . dataset [ ' privacyState' ] = state
164166 form . setAttribute ( 'aria-busy' , String ( state === 'loading' ) )
165167
166168 if ( ! requestType ) {
@@ -172,8 +174,8 @@ export class PrivacyFormElement extends LitElement {
172174 }
173175
174176 private setSubmitLoading ( form : HTMLFormElement , loading : boolean ) : void {
175- const submitButton = form . querySelector ( 'button[type="submit"]' )
176- if ( submitButton instanceof HTMLButtonElement ) {
177+ const submitButton = getPrivacySubmitButton ( form )
178+ if ( submitButton ) {
177179 submitButton . disabled = loading
178180 }
179181 }
@@ -397,13 +399,12 @@ export class PrivacyFormElement extends LitElement {
397399 const isAccessRequest = requestType === 'ACCESS'
398400 const form = isAccessRequest ? this . accessForm : this . deleteForm
399401 const emailInput = isAccessRequest ? this . accessEmailInput : this . deleteEmailInput
400- const prefix = isAccessRequest ? 'access' : 'delete'
401402
402403 // Show only the matching static SSR preview toast; hide all others for this form.
403404 for ( const el of this . getPreviewToastElements ( requestType ) ) {
404405 el . classList . add ( 'hidden' )
405406 }
406- this . querySelector < HTMLElement > ( `# ${ prefix } -preview-toast- ${ previewState } ` ) ?. classList . remove ( 'hidden' )
407+ getPrivacyPreviewToastElement ( requestType , previewState , this ) ?. classList . remove ( 'hidden' )
407408
408409 this . setRequestState ( form , previewState , requestType )
409410 this . setSubmitLoading ( form , previewState === 'loading' )
0 commit comments