<div class="registration-upload-passport registration_hide">
<div class="title">
<div class="registration-form-title">
Please upload a photo of your passport photo page
</div>
</div>
<div class="sub-title">
<div class="registration-form-sub-title">
This should be a JPEG format and no larger than 1.5MB file size. Please ensure that the scan has no reflections and that all information is clearly readable.
</div>
</div>
<div class="registration-error registration-server-error registration_hide" role="alert">
<span class="registration-error-message">sitecore api error</span>
</div>
<div class="registration-upload-passport__image-container" data-face="Image does not contain the correct amount of faces. Please upload a new photo." data-racy="Image moderation has detected possibly racy content. Please upload a new photo." data-adult="Image moderation has detected possibly adult content. Please upload a new photo.">
<img data-allowedSize="5" data-placeholderImage="/assets/example-content/passport.svg" alt="registration passport" class="img" src="/assets/example-content/passport.svg" id="registration-upload-passport__img" loading="lazy" />
</div>
<div class="cta">
<div class="registration-upload-passport__upload-passport-photo">
<a href="/" class="cta cta--r-primary ">
<p>UPLOAD FROM FILES</p>
</a>
</div>
<div class="registration-upload-passport__take-passport-photo-click" data-take-photo="Take photo" data-take-photo-error="Your devices camera is not supported. Please upload a picture of your passport.">
<a href="/" class="cta cta--r-secondary ">
<p>TAKE PHOTO</p>
</a>
</div>
</div>
</div>
No notes defined.
{
"title": {
"copy": "Please upload a photo of your passport photo page"
},
"sub-title": {
"copy": "This should be a JPEG format and no larger than 1.5MB file size. Please ensure that the scan has no reflections and that all information is clearly readable."
},
"take-photo": {
"copy": "Take photo"
},
"take-photo-error": {
"copy": "Your devices camera is not supported. Please upload a picture of your passport."
},
"btn-1": {
"copy": "TAKE PHOTO"
},
"btn-2": {
"copy": "UPLOAD FROM FILES"
}
}
/* eslint-disable no-lonely-if */
/* eslint-disable operator-linebreak */
/* eslint-disable compat/compat */
import { base64Obj, camera, fileUpload } from '../../camera';
import {
hideServerError,
showServerError,
} from '../../registration-server-error/registration-server-error';
import {
POST,
passportUploadPayload,
passportUploadPath,
getAuth,
GET,
imagepath,
} from '../../service';
import {
BACKCLICKED,
NEWPASSPORT,
currentPage,
hideStep,
nevigateToNext,
onComponentVisible,
showStep,
} from '../../registrationUtility';
export default (uploadPassport, passportDetails) => {
const [
previewElement,
uploadFileBtn,
takePhotoBtn,
] = uploadPassport.querySelectorAll(
'.img, .registration-upload-passport__upload-passport-photo .cta--r-primary, .registration-upload-passport__take-passport-photo-click .cta--r-secondary'
);
let controller = new AbortController();
const isFaceAccepted = document
.querySelector('.registration-upload-passport__image-container')
.getAttribute('data-face');
const isRacy = document
.querySelector('.registration-upload-passport__image-container')
.getAttribute('data-racy');
const isAdult = document
.querySelector('.registration-upload-passport__image-container')
.getAttribute('data-adult');
const uploadPhoto = async data => {
const { base64, type } = base64Obj(data);
const auth = getAuth();
const res = await POST(passportUploadPath, {
...passportUploadPayload,
JuniorFancode: !!uploadFileBtn.getAttribute('data-fan'),
FanCode: uploadFileBtn.getAttribute('data-fan')
? uploadFileBtn.getAttribute('data-fan')
: getAuth().fanCode,
ContentLength: base64.length,
ContentType: type,
FileName: `${auth.fanCode}.${type.split('/')[1]}`,
ImageUploadPassport: base64,
});
if (res.success && res.photoUploaded) {
nevigateToNext(uploadPassport);
passportDetails
.querySelector('.passport img')
.setAttribute('data-img', data);
} else {
if (res.isracy && !res.isFaceAccepted) {
showServerError(uploadPassport, isRacy);
} else if (res.isAdult && !res.isFaceAccepted) {
showServerError(uploadPassport, isAdult);
} else if (res.isFaceAccepted !== undefined && !res.isFaceAccepted) {
showServerError(uploadPassport, isFaceAccepted);
} else {
showServerError(uploadPassport, res.error);
}
}
};
onComponentVisible(uploadPassport, async () => {
controller.abort('Removing previous event listeners');
controller = new AbortController();
hideServerError(uploadPassport);
showStep('03');
if (
uploadPassport.classList.contains('registration-upload-passport-cloned')
) {
hideStep();
}
currentPage.page = uploadPassport;
previewElement.setAttribute(
'src',
previewElement.getAttribute('data-placeholderImage')
);
const uploadPhotoHandler = (event, prevEle, upldPas) => {
event.preventDefault();
fileUpload(prevEle, uploadPhoto, upldPas);
};
takePhotoBtn.addEventListener(
'click',
event => {
let parentElement;
const { tagName } = event.target;
if (tagName === 'P') {
parentElement = event.target.parentElement.parentElement;
} else {
parentElement = event.target.parentElement;
}
event.preventDefault();
hideServerError(uploadPassport);
camera(
previewElement,
uploadPhoto,
uploadPassport,
parentElement.attributes[2]
? parentElement.attributes[2].value
: 'Your devices camera is not supported. Please upload a picture of your passport.',
parentElement.attributes[1]
? parentElement.attributes[1].value
: 'Take photo'
);
},
{ signal: controller.signal }
);
uploadFileBtn.addEventListener(
'click',
event => uploadPhotoHandler(event, previewElement, uploadPassport),
{ signal: controller.signal }
);
if (sessionStorage.getItem(NEWPASSPORT)) {
sessionStorage.removeItem(NEWPASSPORT);
} else {
const imageResponse = await GET(
imagepath(
uploadFileBtn.getAttribute('data-fan')
? uploadFileBtn.getAttribute('data-fan')
: getAuth().fanCode,
'Passport'
)
);
if (imageResponse.success) {
passportDetails
.querySelector('.passport img')
.setAttribute('data-img', imageResponse.src);
nevigateToNext(uploadPassport);
}
}
sessionStorage.removeItem(NEWPASSPORT);
sessionStorage.removeItem(BACKCLICKED);
});
};
.registration-upload-passport-cloned,
.registration-upload-passport {
$cta-container-mt: 32px;
$cta-gap: 16px;
$body-mt: 32px;
&__image-container {
margin-top: $body-mt;
img {
margin: auto;
}
}
& > .cta {
margin-top: $cta-container-mt;
.cta--r-secondary,
.cta--r-primary {
min-height: 44px;
font-size: 16px;
}
div:not(:first-child) {
margin-top: $cta-gap;
}
}
@media screen and (max-width: $mq-medium) {
&__take-passport-photo-click {
display: none;
}
}
}
{{!-- adding registration_hide--}}
<div class="registration-upload-passport registration_hide">
<div class="title">
{{render '@registration-form-title' title}}
</div>
<div class="sub-title">
{{render '@registration-form-sub-title' sub-title}}
</div>
{{!-- adding error --}}
{{render '@registration-server-error'}}
<div class="registration-upload-passport__image-container"
data-face="Image does not contain the correct amount of faces. Please upload a new photo."
data-racy="Image moderation has detected possibly racy content. Please upload a new photo."
data-adult="Image moderation has detected possibly adult content. Please upload a new photo.">
<img data-allowedSize="5" data-placeholderImage="/assets/example-content/passport.svg"
alt="registration passport" class="img" src="/assets/example-content/passport.svg"
id="registration-upload-passport__img" loading="lazy" />
</div>
<div class="cta">
<div class="registration-upload-passport__upload-passport-photo">
{{render '@cta--r-primary' btn-2 merge="true"}}
</div>
<div class="registration-upload-passport__take-passport-photo-click" data-take-photo="Take photo"
data-take-photo-error="Your devices camera is not supported. Please upload a picture of your passport.">
{{render '@cta--r-secondary' btn-1 merge="true"}}
</div>
</div>
</div>