feat: refine creation and registration flows
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
import firebase, { usersRef } from '../config/firebase'
|
||||
import { Routes } from '../navigation/Routes'
|
||||
|
||||
export const MUSICLAND_LAUNCH_DATE = null
|
||||
|
||||
export const isGlobalListeningLaunchPeriodActive = (now = new Date()) => {
|
||||
if (!MUSICLAND_LAUNCH_DATE) {
|
||||
return false
|
||||
}
|
||||
|
||||
const launchDate = new Date(MUSICLAND_LAUNCH_DATE)
|
||||
if (Number.isNaN(launchDate.getTime())) {
|
||||
return false
|
||||
}
|
||||
|
||||
const launchPeriodEnd = new Date(launchDate)
|
||||
launchPeriodEnd.setMonth(launchPeriodEnd.getMonth() + 1)
|
||||
|
||||
return now >= launchDate && now < launchPeriodEnd
|
||||
}
|
||||
|
||||
export const getRouteAfterAuthentication = (userData = {}) =>
|
||||
userData?.registrationFlowRequired === true
|
||||
? Routes.RegistrationChoice
|
||||
: Routes.BottomTab
|
||||
|
||||
export const getExperienceReset = (experience) => {
|
||||
if (experience === 'listen') {
|
||||
return {
|
||||
index: 0,
|
||||
routes: [
|
||||
{
|
||||
name: Routes.BottomTab,
|
||||
params: { screen: Routes.HitParade },
|
||||
},
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
index: 0,
|
||||
routes: [
|
||||
{
|
||||
name: Routes.BottomTab,
|
||||
params: {
|
||||
screen: Routes.HomeStack,
|
||||
params: { screen: Routes.Home },
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
export const completeRegistrationFlow = async (experience) => {
|
||||
const uid = firebase.auth().currentUser?.uid
|
||||
if (!uid) {
|
||||
throw new Error('Aucun utilisateur connecté')
|
||||
}
|
||||
|
||||
if (experience !== 'listen' && experience !== 'creation') {
|
||||
throw new Error('Expérience MusicLand inconnue')
|
||||
}
|
||||
|
||||
await usersRef.doc(uid).set(
|
||||
{
|
||||
registrationFlowRequired: false,
|
||||
initialExperience: experience,
|
||||
registrationFlowCompletedAt: firebase.firestore.FieldValue.serverTimestamp(),
|
||||
updatedAt: firebase.firestore.FieldValue.serverTimestamp(),
|
||||
},
|
||||
{ merge: true }
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user