wip on session create in beta site

This commit is contained in:
Nuwan 2023-10-17 08:30:23 +05:30
parent 02f3201cb2
commit 20c02f0f2a
3 changed files with 103 additions and 19 deletions

View File

@ -8,6 +8,12 @@ import JKFriendsAutoComplete from '../people/JKFriendsAutoComplete';
import JKSessionInviteesChips from '../people/JKSessionInviteesChips';
import { getFriends } from '../../helpers/rest';
const privacyMap = {
"public": 1,
"private_invite": 2,
"private_approve": 3
}
const JKNewMusicSession = () => {
const { currentUser } = useAuth();
const { t } = useTranslation();
@ -69,7 +75,9 @@ const JKNewMusicSession = () => {
//window.open jamkazam app url using custom URL scheme
//an example URL would be: jamkazam://url=https://www.jamkazam.com/client#/createSession/privacy~2|description~hello|inviteeIds~1,2,3,4
const q = `privacy~${payload.privacy}|description~${payload.description}|inviteeIds~${payload.inviteeIds}`
window.open(`jamkazam://url=${process.env.REACT_APP_CLIENT_BASE_URL}/client#/createSession/${q}`)
const url = encodeURI(`${process.env.REACT_APP_CLIENT_BASE_URL}/client#/createSession/${q}`)
const urlScheme = `jamkazam://url=${url}`
window.open(urlScheme)
try {
//store this payload in localstorage.
localStorage.setItem('formData', JSON.stringify(payload))
@ -113,9 +121,9 @@ const JKNewMusicSession = () => {
<JKTooltip title={t('new.privacy_help', { ns: 'sessions' })} />
</Label>
<Input type="select" aria-label="Session Privacy" name="privacy" value={privacy} onChange={(e) => setPrivacy(e.target.value)} data-testid="session-privacy">
<option value="1">{t('new.privacy_opt_public', { ns: 'sessions' })}</option>
<option value="2">{t('new.privacy_opt_private_invite', { ns: 'sessions' })}</option>
<option value="3">{t('new.privacy_opt_private_approve', { ns: 'sessions' })}</option>
<option value={privacyMap["public"]}>{t('new.privacy_opt_public', { ns: 'sessions' })}</option>
<option value={privacyMap["private_invite"]}>{t('new.privacy_opt_private_invite', { ns: 'sessions' })}</option>
<option value={privacyMap["private_approve"]}>{t('new.privacy_opt_private_approve', { ns: 'sessions' })}</option>
</Input>
</FormGroup>

View File

@ -1077,13 +1077,19 @@
}
function createMusicianInvite(options) {
return $.ajax({
type: "POST",
dataType: "json",
url: '/api/invitations',
contentType: 'application/json',
processData: false,
data: JSON.stringify(options)
return new Promise(function(resolve, reject){
$.ajax({
type: "POST",
dataType: "json",
url: '/api/invitations',
contentType: 'application/json',
processData: false,
data: JSON.stringify(options)
}).done(function(resp){
resolve(resp)
}).fail(function(xhr){
reject(xhr)
})
})
}

View File

@ -101,6 +101,12 @@
"5": "Adv"
};
var privacyMap = {
"public": "1",
"private_invite": "2",
"private_approve": "3"
}
function afterLoadScheduledSessions(sessionList) {
$featureSessions.empty()
@ -570,7 +576,8 @@
createSessionSettings.timezone.label = "(GMT-06:00) Central Time (US & Canada)";
createSessionSettings.timezone.value = "Central Time (US & Canada),America/Chicago";
createSessionSettings.name = "Open Session";
createSessionSettings.description = "Feel free to join this session, it's open!";
if(createSessionSettings.description === undefined || createSessionSettings.description.length === 0)
createSessionSettings.description = "Feel free to join this session, it's open!";
createSessionSettings.notations = [];
createSessionSettings.language.label = 'English';
createSessionSettings.language.value = 'eng';
@ -908,7 +915,7 @@
logger.debug("created session on server");
$('#create-session-buttons .btn-next').off('click');
var newSessionId = response.id;
createSessionSettings.newSessionId = newSessionId
if (createSessionSettings.createType == '<%= MusicSession::CREATE_TYPE_QUICK_START %>' || createSessionSettings.createType == "immediately" || createSessionSettings.createType == '<%= MusicSession::CREATE_TYPE_QUICK_PUBLIC %>') {
joinSession(newSessionId);
}
@ -1518,21 +1525,80 @@
}
//handle jamkazam:// custom URL scheme params
function decodeCustomSchemaParams(){
const hash = context.location.hash;
//when a user submits create new session form (in the new react website)
//this custom url scheme is loaded and as a result the JamKazam app loads create session window.
function initCustomUrlScheme(){
//an example URL would be: https://www.jamkazam.com/client#/createSession/privacy~2|description~hello|inviteeIds~1,2,3,4
const hash = decodeURIComponent(context.location.hash);
const qStr = hash.substring(hash.lastIndexOf('/') + 1);
//an example URL would be: https://www.jamkazam.com/client#/createSession/privacy~2|description~hello|inviteeIds~1,2,3,4
//decode the query params according to the custom format
const qParamsArr = qStr.split('|');
let privacy, description, inviteeIds;
qParamsArr.each(function(q){
qParamsArr.forEach(function(q){
const qp = q.split('~')
if(qp[0] === 'privacy') privacy = qp[1]
if(qp[0] === 'description') description = qp[1]
if(qp[0] === 'inviteeIds') inviteeIds = qp[1]
if(qp[0] === 'inviteeIds') inviteeIds = qp[1]
})
createSessionSettings.description = description;
alert(description)
switch(privacy){
case privacyMap['private_invite']:
clickQuickStartFriends();
break;
case privacyMap['private_approve']:
clickQuickStartSolo()
break;
case privacyMap['public']:
clickQuickStartPublic();
break;
default:
logger.debug('Invalid session privacy value')
return
}
waitUntilSessionCreated().then(function(){
//now async send invitations
if(createSessionSettings.newSessionId && inviteeIds !== undefined){
const inviteUserIds = inviteeIds.split(',');
inviteUserIds.forEach(function(inviteId){
const invite = {
music_session: createSessionSettings.newSessionId,
receiver: inviteId
};
rest.createMusicianInvite(invite).then(function(resp){
console.log("Invitation was sent")
}).catch(function(error){
logger.debug(error)
})
})
}
}).catch(function(error){
logger.debug(error)
});
}
function waitUntilSessionCreated(){
return new Promise(function(resolve, reject){
const maxAttempts = 5;
let attempt = 0;
try{
const sessionCreateInterval = setInterval(function(){
attempt++;
console.log('_DEBUG_ trying to get the sessionId....', attempt)
if(createSessionSettings.newSessionId){
clearInterval(sessionCreateInterval)
resolve()
}else if(attempt > maxAttempts){
reject("Maximum number of attepts for getting a sessionId is exceeded.")
}
}, 1000)
}catch(error){
reject(error)
}
})
}
function initialize(invitationDialogInstance, friendSelectorDialog, instrumentSelectorInstance, instrumentRSVPSelectorInstance) {
@ -1583,6 +1649,10 @@
initializeControls();
events();
setTimeout(function(){
initCustomUrlScheme();
}, 1000);
}
this.initialize = initialize;