<div class="registration-upload-profile registration_hide">
<div class="title">
<div class="registration-form-title">
Please upload a profile photo
</div>
</div>
<div class="sub-title">
<div class="registration-form-sub-title" data-instruction1="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." data-instruction2="Please resize and edit until you’re happy" data-instruction3="title 3">
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-profile__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/account_box.svg" alt="registration passport" class="registration-upload-profile__img" src="/assets/example-content/account_box.svg" id="rregistration-upload-profile__img" />
</div>
<div class="cta registration-image-upload-btn-container">
<div class="registration-upload-profile__upload-profile-photo">
<a href="/" class="cta cta--r-primary " id="btnUploadPhoto">
<p>UPLOAD FROM FILES</p>
</a>
</div>
<div class="registration-upload-profile__take-profile-photo-click" data-take-photo="Take photo" data-take-photo-error="Your devices camera is not supported. Please upload your profile picture.">
<a href="/" class="cta cta--r-secondary " id="btnTakePhoto">
<p>TAKE PHOTO</p>
</a>
</div>
</div>
<div class="cta registration-image-crop-btn-container registration_hide">
<div class="registration-image-crop-zoom-container">
<span class="registration-image-crop-zoom-label">ZOOM</span>
<div id="cropme-slider"></div>
</div>
<div class="registration-image-crop-rotate-container">
<span class="registration-image-crop-rotate-label">ROTATE</span>
<div id="cropme-rotation-slider"></div>
</div>
<div class="registration-upload-profile__next_btn">
<a href="/" class="cta cta--r-primary " id="nextBtn">
<p>NEXT</p>
</a>
</div>
<div class="registration-upload-profile__take-new-photo">
<a href="/" class="cta cta--r-secondary " id="uploadNewPhoto">
<p>UPLOAD NEW PHOTO (OPTIONAL)</p>
</a>
</div>
</div>
</div>
No notes defined.
{
"title": {
"copy": "Please upload a profile photo"
},
"sub-title": {
"title1": "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.",
"title2": "Please resize and edit until you’re happy",
"title3": "title 3"
},
"take-photo": {
"copy": "Take photo"
},
"take-photo-error": {
"copy": "Your devices camera is not supported. Please upload your profile picture."
},
"btn-1": {
"copy": "TAKE PHOTO",
"id": "btnTakePhoto"
},
"btn-2": {
"copy": "UPLOAD FROM FILES",
"id": "btnUploadPhoto"
},
"btn-3": {
"copy": "NEXT",
"id": "nextBtn"
},
"btn-4": {
"copy": "UPLOAD NEW PHOTO (OPTIONAL)",
"id": "uploadNewPhoto"
}
}
/* eslint-disable no-lonely-if */
/* eslint-disable operator-linebreak */
/* eslint-disable compat/compat */
import Cropme from 'cropme';
import { base64Obj, camera, fileUpload } from '../../camera';
import { hideClass } from '../../registration-error/registration-error';
import {
hideRegistrationLoader,
showRegistrationLoader,
} from '../../registration-loader/registration-loader';
import {
hideServerError,
showServerError,
} from '../../registration-server-error/registration-server-error';
import {
currentPage,
hideStep,
nevigateToNext,
onComponentVisible,
setTitle,
showStep,
} from '../../registrationUtility';
import {
GET,
POST,
getAuth,
imagepath,
profileUploadPath,
profileUploadPayload,
} from '../../service';
export default currentElement => {
let controller = new AbortController();
let cropmeInstance;
onComponentVisible(currentElement, async () => {
controller.abort('Removing previous event listeners');
controller = new AbortController();
const [
title,
previewElementContainer,
previewElement,
imageUploadBtnContainer,
uploadProfilePhotoCta,
takeProfilePhotoCta,
imageCropBtnContainer,
zoomContainer,
rotateContainer,
nextCtn,
takenewPhotoCta,
] = currentElement.querySelectorAll(
'.registration-form-sub-title, .registration-upload-profile__image-container, .registration-upload-profile__img, .registration-image-upload-btn-container, .registration-upload-profile__upload-profile-photo .cta, .registration-upload-profile__take-profile-photo-click .cta, .registration-image-crop-btn-container, .registration-image-crop-zoom-container, .registration-image-crop-rotate-container, .registration-upload-profile__next_btn .cta, .registration-upload-profile__take-new-photo .cta'
);
const isFaceAccepted = currentElement
.querySelector('.registration-upload-profile__image-container')
.getAttribute('data-face');
const isRacy = currentElement
.querySelector('.registration-upload-profile__image-container')
.getAttribute('data-racy');
const isAdult = currentElement
.querySelector('.registration-upload-profile__image-container')
.getAttribute('data-adult');
const initiateCropme = _previewElement => {
showRegistrationLoader();
cropmeInstance = new Cropme(_previewElement, {
container: {
width: '100%',
height: 222,
},
viewport: {
width: 200,
height: 200,
type: 'square',
border: {
width: '1',
enable: true,
color: '#fff',
},
},
zoom: {
enable: true,
mouseWheel: true,
slider: true,
},
rotation: {
slider: true,
enable: true,
position: 'left',
},
transformOrigin: 'image',
customClass: 'cropme-custom-class',
});
hideRegistrationLoader();
return cropmeInstance;
};
const destroyCropme = () => {
if (currentElement.querySelector('.cropme-wrapper') && cropmeInstance) {
cropmeInstance.destroy();
}
if (!currentElement.querySelector('.registration-upload-profile__img')) {
previewElement.style = '';
previewElementContainer.appendChild(previewElement);
}
};
destroyCropme();
cropmeInstance = undefined;
const initializeSliders = () => {
const [_customZoom, _customRotate] = currentElement.querySelectorAll(
'.registration-image-crop-zoom-container #cropme-slider, .registration-image-crop-rotate-container #cropme-rotation-slider'
);
const [
_zoomContainer,
_rotateContainer,
] = currentElement.querySelectorAll(
'.cropme-wrapper .cropme-slider, .cropme-wrapper .cropme-rotation-slider'
);
if (
_customZoom.querySelector('input') &&
_customRotate.querySelector('input')
) {
_customZoom.querySelector('input').remove();
_customRotate.querySelector('input').remove();
}
_customRotate.parentElement.classList.remove(hideClass);
_customZoom.parentElement.classList.remove(hideClass);
_customZoom.appendChild(_zoomContainer.querySelector('input'));
_customRotate.appendChild(_rotateContainer.querySelector('input'));
_zoomContainer.remove();
_rotateContainer.remove();
};
const setInitialState = () => {
destroyCropme();
showRegistrationLoader();
hideServerError(currentElement);
previewElement.setAttribute(
'src',
previewElement.getAttribute('data-placeholderImage')
);
setTitle(currentElement, title.getAttribute('data-instruction1'));
imageUploadBtnContainer.classList.remove(hideClass);
imageCropBtnContainer.classList.add(hideClass);
zoomContainer.classList.add(hideClass);
rotateContainer.classList.add(hideClass);
hideRegistrationLoader();
};
currentPage.page = currentElement;
showStep('04');
if (
currentElement.classList.contains('registration-upload-profile-cloned')
) {
hideStep();
}
setInitialState();
const profileRes = await GET(
imagepath(
nextCtn.getAttribute('data-fan')
? nextCtn.getAttribute('data-fan')
: getAuth().fanCode,
'Photo'
)
);
if (profileRes.success) {
setTitle(currentElement, title.getAttribute('data-instruction3'));
previewElement.setAttribute('src', profileRes.src);
imageUploadBtnContainer.classList.add(hideClass);
imageCropBtnContainer.classList.remove(hideClass);
}
const profilePhotoCallback = imageData => {
destroyCropme();
cropmeInstance = initiateCropme(previewElement);
setTitle(currentElement, title.getAttribute('data-instruction2'));
previewElement.setAttribute('src', imageData);
initializeSliders();
hideServerError(currentElement);
imageUploadBtnContainer.classList.add(hideClass);
imageCropBtnContainer.classList.remove(hideClass);
};
uploadProfilePhotoCta.addEventListener(
'click',
event => {
event.preventDefault();
// hideServerError(currentElement);
fileUpload(previewElement, profilePhotoCallback, currentElement);
},
{ signal: controller.signal }
);
takeProfilePhotoCta.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(currentElement);
camera(
previewElement,
profilePhotoCallback,
currentElement,
parentElement.attributes[2]
? parentElement.attributes[2].value
: 'Your devices camera is not supported. Please upload your profile picture.',
parentElement.attributes[1]
? parentElement.attributes[1].value
: 'Take photo'
);
},
{ signal: controller.signal }
);
nextCtn.addEventListener(
'click',
// eslint-disable-next-line complexity
async event => {
event.preventDefault();
if (!currentElement.querySelector('.cropme-wrapper')) {
nevigateToNext(currentElement);
} else {
const auth = getAuth();
const fanCode = nextCtn.getAttribute('data-fan')
? nextCtn.getAttribute('data-fan')
: auth.fanCode;
const cropperImage = await cropmeInstance.crop();
const { base64, type } = base64Obj(cropperImage);
const profileResData = await POST(profileUploadPath, {
...profileUploadPayload,
JuniorFancode: !!nextCtn.getAttribute('data-fan'),
FanCode: fanCode,
ContentLength: base64.length,
ContentType: type,
FileName: `${fanCode}.${type.split('/')[1]}`,
ImageUploadPhoto: base64,
});
if (profileResData.success && profileResData.photoUploaded) {
destroyCropme();
nevigateToNext(currentElement);
} else {
if (profileResData.isracy && !profileResData.isFaceAccepted) {
showServerError(currentElement, isRacy);
} else if (
profileResData.isAdult &&
!profileResData.isFaceAccepted
) {
showServerError(currentElement, isAdult);
} else if (
profileResData.isFaceAccepted !== undefined &&
!profileResData.isFaceAccepted
) {
showServerError(currentElement, isFaceAccepted);
} else {
showServerError(currentElement, profileResData.error);
}
}
}
},
{ signal: controller.signal }
);
takenewPhotoCta.addEventListener(
'click',
event => {
event.preventDefault();
setInitialState();
},
{ signal: controller.signal }
);
});
};
@import './../../../../../../node_modules/cropme/src/cropme';
.registration-upload-profile-cloned,
.registration-upload-profile {
$cta-container-mt: 40px;
$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;
}
}
&__take-profile-photo-click,
&__take-new-photo {
margin-top: $cta-gap;
}
@media screen and (max-width: $mq-medium) {
&__take-profile-photo-click {
display: none;
}
}
.cropme-custom-class {
.cropme-container {
background: #f5f5f5;
}
img {
margin: 0;
}
}
.cropme-slider input,
.cropme-rotation-slider input {
-webkit-appearance: auto !important;
appearance: auto !important;
}
.registration-image-crop-btn-container input[type='range'] {
accent-color: white; /* stylelint-disable-line */
width: 100% !important;
height: 3px;
margin: 15px 0 0 0;
}
.registration-image-crop-zoom-label,
.registration-image-crop-rotate-label {
font: $registration-font;
font-weight: 400;
font-size: 16px;
color: white;
}
.registration-image-crop-rotate-container {
margin: 40px 0;
}
}
<div class="registration-upload-profile registration_hide">
<div class="title">
{{render '@registration-form-title' title}}
</div>
<div class="sub-title">
<div class="registration-form-sub-title" data-instruction1="{{sub-title.title1}}"
data-instruction2="{{sub-title.title2}}" data-instruction3="{{sub-title.title3}}">
{{sub-title.title1}}
</div>
</div>
{{render '@registration-server-error'}}
<div class="registration-upload-profile__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/account_box.svg"
alt="registration passport" class="registration-upload-profile__img"
src="/assets/example-content/account_box.svg" id="rregistration-upload-profile__img" />
</div>
{{!-- state 1--}}
<div class="cta registration-image-upload-btn-container">
<div class="registration-upload-profile__upload-profile-photo">
{{render '@cta--r-primary' btn-2 merge="true"}}
</div>
<div class="registration-upload-profile__take-profile-photo-click" data-take-photo="Take photo"
data-take-photo-error="Your devices camera is not supported. Please upload your profile picture.">
{{render '@cta--r-secondary' btn-1 merge="true"}}
</div>
</div>
<div class="cta registration-image-crop-btn-container registration_hide">
{{!-- state 2 --}}
<div class="registration-image-crop-zoom-container">
<span class="registration-image-crop-zoom-label">ZOOM</span>
<div id="cropme-slider"></div>
</div>
<div class="registration-image-crop-rotate-container">
<span class="registration-image-crop-rotate-label">ROTATE</span>
<div id="cropme-rotation-slider"></div>
</div>
{{!-- state 3 --}}
<div class="registration-upload-profile__next_btn">
{{render '@cta--r-primary' btn-3 merge="true"}}
</div>
<div class="registration-upload-profile__take-new-photo">
{{render '@cta--r-secondary' btn-4 merge="true"}}
</div>
</div>
</div>