}
@@ -32,6 +32,7 @@ const SubmitWizard = ({ eventId, cfpOpened, eventName, currentStep }) => {
}
SubmitWizard.propTypes = {
+ userId: PropTypes.string,
eventId: PropTypes.string,
cfpOpened: PropTypes.bool,
eventName: PropTypes.string,
@@ -39,6 +40,7 @@ SubmitWizard.propTypes = {
}
SubmitWizard.defaultProps = {
+ userId: undefined,
eventId: undefined,
cfpOpened: false,
eventName: undefined,
diff --git a/src/screens/speaker/event/submitWizard/talksSelection/talksSelection.container.js b/src/screens/speaker/event/submitWizard/talksSelection/talksSelection.container.js
index 5b4ad698a..99024e380 100644
--- a/src/screens/speaker/event/submitWizard/talksSelection/talksSelection.container.js
+++ b/src/screens/speaker/event/submitWizard/talksSelection/talksSelection.container.js
@@ -3,13 +3,13 @@ import { inject } from '@k-ramel/react'
import loader from 'components/loader'
import TalksSelection from './talksSelection'
-const mapStore = (store, { eventId }) => {
+const mapStore = (store, { userId, eventId }) => {
const talks = store.ui.speaker.myTalks.getAsArray().filter((talk) => !talk.archived)
return {
loaded: store.ui.speaker.myTalks.isInitialized(),
talks,
- load: () => store.dispatch('@@ui/ON_LOAD_SPEAKER_TALKS'),
+ load: () => store.dispatch({ type: '@@ui/ON_LOAD_SPEAKER_TALKS', payload: { userId } }),
onSelect: (talkId) => {
store.dispatch({ type: '@@ui/GO_TO_EVENT_SUBMISSION', payload: { eventId, talkId } })
},
diff --git a/src/screens/speaker/event/survey/survey.container.js b/src/screens/speaker/event/survey/survey.container.js
index 90b6a31fa..c197cc3a1 100644
--- a/src/screens/speaker/event/survey/survey.container.js
+++ b/src/screens/speaker/event/survey/survey.container.js
@@ -6,13 +6,11 @@ import loader from 'components/loader'
import SpeakerSurvey from './survey'
const mapState = (store, props, { router }) => {
- const { uid } = store.auth.get()
const eventId = router.getParam('eventId')
const { name } = store.data.events.get(eventId) || {}
return {
- loaded: store.data.events.hasKey(eventId),
- uid,
name,
+ loaded: store.data.events.hasKey(eventId),
load: () => store.dispatch({ type: '@@ui/ON_LOAD_EVENT', payload: eventId }),
}
}
diff --git a/src/screens/speaker/event/survey/survey.jsx b/src/screens/speaker/event/survey/survey.jsx
index 201c62135..e95301628 100644
--- a/src/screens/speaker/event/survey/survey.jsx
+++ b/src/screens/speaker/event/survey/survey.jsx
@@ -3,25 +3,28 @@ import PropTypes from 'prop-types'
import EventTitle from 'screens/components/event/eventTitle'
import SurveyForm from 'screens/components/event/survey/form'
+import { useAuth } from 'features/auth'
import './survey.css'
-const SpeakerSurvey = ({ uid, name }) => (
-
-
-
-
- Organizers need some information about you in order to make a better event experience for
- speakers. Please fill the following survey to help them.
-
-
+const SpeakerSurvey = ({ name }) => {
+ const { user } = useAuth()
+ return (
+
+
+
+
+ Organizers need some information about you in order to make a better event experience for
+ speakers. Please fill the following survey to help them.
+
+
+
-
-)
+ )
+}
SpeakerSurvey.propTypes = {
name: PropTypes.string.isRequired,
- uid: PropTypes.string.isRequired,
}
export default SpeakerSurvey
diff --git a/src/screens/speaker/sidebar/index.js b/src/screens/speaker/sidebar/index.js
index 8b1d143d1..f47730965 100644
--- a/src/screens/speaker/sidebar/index.js
+++ b/src/screens/speaker/sidebar/index.js
@@ -1 +1 @@
-export { default } from './sidebar.container'
+export { default } from './sidebar'
diff --git a/src/screens/speaker/sidebar/sidebar.container.js b/src/screens/speaker/sidebar/sidebar.container.js
deleted file mode 100644
index 380f90263..000000000
--- a/src/screens/speaker/sidebar/sidebar.container.js
+++ /dev/null
@@ -1,13 +0,0 @@
-import { inject } from '@k-ramel/react'
-
-import Sidebar from './sidebar'
-
-const mapStore = (store) => {
- const { uid } = store.auth.get()
- const { displayName } = store.data.users.get(uid) || {}
- return {
- fullname: displayName,
- }
-}
-
-export default inject(mapStore)(Sidebar)
diff --git a/src/screens/speaker/sidebar/sidebar.jsx b/src/screens/speaker/sidebar/sidebar.jsx
index dad3cc8f7..c75949b2e 100644
--- a/src/screens/speaker/sidebar/sidebar.jsx
+++ b/src/screens/speaker/sidebar/sidebar.jsx
@@ -1,31 +1,33 @@
import React from 'react'
import PropTypes from 'prop-types'
+import { useAuth } from 'features/auth'
import { SideBar, SideBarPanel, SideBarLink } from 'layout/sidebar'
import IconLabel from 'components/iconLabel'
import EventSidebar from './event'
-const SpeakerSideBar = ({ fullname, className }) => (
-
-
-
-
-
-
-
-
-
-
-
-)
+const SpeakerSideBar = ({ className }) => {
+ const { user } = useAuth()
+ return (
+
+
+
+
+
+
+
+
+
+
+
+ )
+}
SpeakerSideBar.propTypes = {
- fullname: PropTypes.string,
className: PropTypes.string,
}
SpeakerSideBar.defaultProps = {
- fullname: undefined,
className: undefined,
}
diff --git a/src/screens/speaker/speaker.jsx b/src/screens/speaker/speaker.jsx
index 130d64c0c..73e44ed62 100644
--- a/src/screens/speaker/speaker.jsx
+++ b/src/screens/speaker/speaker.jsx
@@ -1,11 +1,12 @@
-import React from 'react'
+import React, { memo } from 'react'
import { compose } from 'redux'
import { forRoute } from '@k-redux-router/react-k-ramel'
-import { protect } from 'store/reducers/auth'
import AppLayout from 'layout'
import Contributors from 'screens/components/contributors'
import Profile from 'screens/components/profile'
+import { useAuth, protect } from 'features/auth'
+
import Sidebar from './sidebar'
import MyTalks from './talks'
import { TalkEdit, TalkCreate } from './talk/form'
@@ -17,21 +18,24 @@ import EventSubmissions from './event/submissions'
import EventSubmissionPage from './event/submission'
import EventSurvey from './event/survey'
-const Speaker = () => (
-
}>
-
-
-
-
-
-
-
-
-
-
-
-
-
-)
+const Speaker = () => {
+ const { user } = useAuth()
+ return (
+
}>
+
+
+
+
+
+
+
+
+
+
+
+
+
+ )
+}
-export default compose(forRoute('speaker'), protect)(Speaker)
+export default compose(memo, forRoute('speaker'), protect)(Speaker)
diff --git a/src/screens/speaker/talk/form/talkCreate.container.js b/src/screens/speaker/talk/form/talkCreate.container.js
index 94ba82388..afc073037 100644
--- a/src/screens/speaker/talk/form/talkCreate.container.js
+++ b/src/screens/speaker/talk/form/talkCreate.container.js
@@ -4,10 +4,10 @@ import { forRoute } from '@k-redux-router/react-k-ramel'
import TalkForm from './talkForm'
-const mapStore = (store) => ({
+const mapStore = (store, { userId }) => ({
submitting: store.ui.loaders.get().isTalkSaving,
- onSubmit: (payload) => {
- store.dispatch({ type: '@@ui/ON_CREATE_TALK', payload })
+ onSubmit: (data) => {
+ store.dispatch({ type: '@@ui/ON_CREATE_TALK', payload: { userId, data } })
},
})
diff --git a/src/screens/speaker/talks/myTalks.container.js b/src/screens/speaker/talks/myTalks.container.js
index d22ba9ebb..2cd6ab10f 100644
--- a/src/screens/speaker/talks/myTalks.container.js
+++ b/src/screens/speaker/talks/myTalks.container.js
@@ -5,10 +5,10 @@ import { forRoute } from '@k-redux-router/react-k-ramel'
import loader from 'components/loader'
import MyTalks from './myTalks'
-const mapStore = (store, props, { router }) => ({
+const mapStore = (store, { userId }, { router }) => ({
loaded: store.ui.speaker.myTalks.isInitialized(),
talks: store.ui.speaker.myTalks.getAsArray(),
- load: () => store.dispatch('@@ui/ON_LOAD_SPEAKER_TALKS'),
+ load: () => store.dispatch({ type: '@@ui/ON_LOAD_SPEAKER_TALKS', payload: { userId } }),
onSelect: (talkId) => router.push('speaker-talk-page', { talkId }),
})
diff --git a/src/store/listeners.js b/src/store/listeners.js
index 3a52cbee3..e7328ac1f 100644
--- a/src/store/listeners.js
+++ b/src/store/listeners.js
@@ -2,8 +2,6 @@ import { when } from 'k-ramel'
import * as app from './reactions/app'
import * as router from './reactions/router'
-import * as auth from './reactions/auth'
-import * as firebase from './reactions/firebase'
import * as user from './reactions/user'
import * as talks from './reactions/talks'
import * as events from './reactions/events'
@@ -15,21 +13,13 @@ import * as survey from './reactions/survey'
export default [
/* app loaded */
- when('@@krml/INIT')(firebase.init),
when('@@krml/INIT')(app.init),
/* router */
when('@@router/ROUTE_FOUND')(router.onRouteChanged),
when('@@router/REPLACE_WITH_NEXT_URL')(router.replaceWithNextUrl),
when('@@router/REDIRECT_TO_NEXT_URL')(router.redirectToNextUrl),
- /* firebase actions */
- when('@@firebase/SIGNED_IN')(auth.signedIn),
- when('@@firebase/SIGNED_OUT')(auth.signedOut),
- /* authentication */
- when('@@ui/SIGN_IN')(auth.signin),
- when('@@ui/SIGN_OUT')(auth.signout),
/* user */
when('@@ui/FETCH_USER')(user.fetchUser),
- when('@@ui/SAVE_PROFILE')(user.saveProfile),
/* talks */
when('@@ui/ON_CREATE_TALK')(talks.createTalk),
when('@@ui/ON_UPDATE_TALK')(talks.updateTalk),
diff --git a/src/store/reactions/auth.js b/src/store/reactions/auth.js
deleted file mode 100644
index 93f151b13..000000000
--- a/src/store/reactions/auth.js
+++ /dev/null
@@ -1,68 +0,0 @@
-import firebase from 'firebase/app'
-import pick from 'lodash/pick'
-
-import userCrud from 'firebase/user'
-import { fetchUserOrganizations } from 'firebase/organizations'
-
-export const signin = (action) => {
- const providerId = action.payload
- let provider
- switch (providerId) {
- case 'google':
- provider = new firebase.auth.GoogleAuthProvider()
- break
- case 'twitter':
- provider = new firebase.auth.TwitterAuthProvider()
- break
- case 'github':
- provider = new firebase.auth.GithubAuthProvider()
- break
- case 'facebook':
- provider = new firebase.auth.FacebookAuthProvider()
- break
- default:
- return
- }
- provider.setCustomParameters({
- prompt: 'select_account',
- })
-
- firebase.auth().signInWithRedirect(provider)
-}
-
-export const signout = (action, store, { router }) => {
- firebase.auth().signOut()
- router.push('home')
- localStorage.removeItem('currentEventId')
-}
-
-export const signedIn = async (action, store) => {
- let user = pick(action.payload, ['uid', 'displayName', 'photoURL', 'email'])
-
- // set auth authenticated
- store.auth.update({ authenticated: true, uid: user.uid })
-
- // check if user exists in database
- const userRef = await userCrud.read(user.uid)
- if (userRef.exists) {
- // get user info from db
- user = userRef.data()
- } else {
- // first connexion, add user in database
- await userCrud.create(user)
- }
- // add user in store
- store.data.users.add(user)
-
- // get users organizations
- const organizations = await fetchUserOrganizations(user.uid)
- store.data.organizations.set(organizations)
-
- // go to the redirect url if exists
- store.dispatch('@@router/REDIRECT_TO_NEXT_URL')
-}
-
-export const signedOut = (action, store) => {
- store.auth.update({ authenticated: false, uid: undefined })
- store.data.users.reset()
-}
diff --git a/src/store/reactions/events.js b/src/store/reactions/events.js
index 6b57df181..50e1e4404 100644
--- a/src/store/reactions/events.js
+++ b/src/store/reactions/events.js
@@ -12,9 +12,8 @@ import eventCrud, {
} from 'firebase/events'
export const createEvent = async (action, store, { router }) => {
- const { uid } = store.auth.get()
- const eventData = action.payload
- const event = { ...eventData, owner: uid }
+ const { userId, data } = action.payload
+ const event = { ...data, owner: userId }
store.ui.loaders.update({ isEventSaving: true })
const ref = await eventCrud.create(event)
@@ -81,10 +80,10 @@ export const fetchEvent = async (action, store, { router }) => {
}
export const fetchOrganizerEvents = async (action, store, { router }) => {
- const { uid } = store.auth.get()
+ const { userId } = action.payload
const organizations = store.data.organizations.getKeys()
- const result = await fetchUserEvents(uid)
+ const result = await fetchUserEvents(userId)
const events = result.docs.map((ref) => ({ id: ref.id, ...ref.data() }))
const organizationsEvents = await Promise.all(
map(organizations, async (organizationId) => {
diff --git a/src/store/reactions/firebase.js b/src/store/reactions/firebase.js
deleted file mode 100644
index 445438247..000000000
--- a/src/store/reactions/firebase.js
+++ /dev/null
@@ -1,19 +0,0 @@
-/* eslint-disable no-console, import/prefer-default-export */
-import firebase from 'firebase/app'
-import 'firebase/auth'
-import 'firebase/firestore'
-import 'firebase/functions'
-import 'firebase/storage'
-
-import { preloadFunctions } from 'firebase/functionCalls'
-
-export const init = (action, store) => {
- firebase.auth().onAuthStateChanged((user) => {
- if (user) {
- store.dispatch({ type: '@@firebase/SIGNED_IN', payload: user })
- preloadFunctions()
- } else {
- store.dispatch('@@firebase/SIGNED_OUT')
- }
- })
-}
diff --git a/src/store/reactions/organizations.js b/src/store/reactions/organizations.js
index 339fae3af..49303e877 100644
--- a/src/store/reactions/organizations.js
+++ b/src/store/reactions/organizations.js
@@ -4,9 +4,11 @@ import organizationCrud, { fetchUserOrganizations } from 'firebase/organizations
import { ROLES } from 'firebase/constants'
export const create = async (action, store, { router }) => {
- const data = action.payload
- const { uid } = store.auth.get()
- const newUserOrganization = flow(set(`members.${uid}`, ROLES.OWNER), set(ROLES.OWNER, uid))(data)
+ const { userId, data } = action.payload
+ const newUserOrganization = flow(
+ set(`members.${userId}`, ROLES.OWNER),
+ set(ROLES.OWNER, userId),
+ )(data)
store.ui.loaders.update({ isOrganizationSaving: true })
const ref = await organizationCrud.create(newUserOrganization)
@@ -38,8 +40,8 @@ export const get = async (action, store, { router }) => {
}
export const ofUser = async (action, store) => {
- const { uid } = store.auth.get()
- const organizations = await fetchUserOrganizations(uid)
+ const { userId } = action.payload
+ const organizations = await fetchUserOrganizations(userId)
store.data.organizations.set(organizations)
}
diff --git a/src/store/reactions/ratings.js b/src/store/reactions/ratings.js
index 94d307f1e..8d9ea3483 100644
--- a/src/store/reactions/ratings.js
+++ b/src/store/reactions/ratings.js
@@ -13,20 +13,19 @@ export const fetchRatings = async (action, store) => {
}
export const rateProposal = async (action, store, { router }) => {
- const rating = action.payload
+ const { rating, feeling, userId } = action.payload
// select needed inputs in the state
- const { uid } = store.auth.get()
const eventId = router.getParam('eventId')
const proposalId = router.getParam('proposalId')
// add or remove the rating in database and store
- const rated = !!rating.rating || !!rating.feeling
+ const rated = !!rating || !!feeling
if (rated) {
- await addRating(eventId, proposalId, uid, rating)
- store.data.ratings.addOrUpdate({ uid, ...rating })
+ await addRating(eventId, proposalId, userId, { rating, feeling })
+ store.data.ratings.addOrUpdate({ uid: userId, rating, feeling })
} else {
- await deleteRating(eventId, proposalId, uid)
- store.data.ratings.remove([uid])
+ await deleteRating(eventId, proposalId, userId)
+ store.data.ratings.remove([userId])
}
// retrieve all ratings before updating proposal computed
@@ -43,6 +42,6 @@ export const rateProposal = async (action, store, { router }) => {
noopinion,
}
// save the rating average in database and store
- updateRating(eventId, proposalId, uid, ratingUpdated, rated)
+ updateRating(eventId, proposalId, userId, ratingUpdated, rated)
store.data.proposals.update({ id: proposalId, ...ratingUpdated })
}
diff --git a/src/store/reactions/talks.js b/src/store/reactions/talks.js
index c08baab62..02523fb80 100644
--- a/src/store/reactions/talks.js
+++ b/src/store/reactions/talks.js
@@ -3,15 +3,14 @@ import { set, unset } from 'immutadot'
import talkCrud, { fetchUserTalks } from 'firebase/talks'
export const createTalk = async (action, store, { router }) => {
- const talk = action.payload
- const { uid } = store.auth.get()
+ const { userId, data } = action.payload
store.ui.loaders.update({ isTalkSaving: true })
const ref = await talkCrud.create({
- ...talk,
- owner: uid,
+ ...data,
+ owner: userId,
archived: false,
- speakers: { [uid]: true },
+ speakers: { [userId]: true },
})
store.ui.loaders.update({ isTalkSaving: false })
@@ -51,8 +50,8 @@ export const fetchTalk = async (action, store, { router }) => {
}
export const fetchSpeakerTalks = async (action, store) => {
- const { uid } = store.auth.get()
- const talks = await fetchUserTalks(uid)
+ const { userId } = action.payload
+ const talks = await fetchUserTalks(userId)
// set talks in the store
store.data.talks.set(talks)
// set talks id to the speaker talk store
diff --git a/src/store/reactions/user.js b/src/store/reactions/user.js
index 1966e3bad..d901eef38 100644
--- a/src/store/reactions/user.js
+++ b/src/store/reactions/user.js
@@ -1,3 +1,4 @@
+/* eslint-disable import/prefer-default-export */
import userCrud from 'firebase/user'
export const fetchUser = async (action, store) => {
@@ -12,13 +13,3 @@ export const fetchUser = async (action, store) => {
store.data.users.add(userRef.data())
}
}
-
-export const saveProfile = async (action, store) => {
- const profile = action.payload
-
- store.ui.loaders.update({ isProfileSaving: true })
- await userCrud.update(profile)
- store.ui.loaders.update({ isProfileSaving: false })
-
- store.data.users.update(profile)
-}
diff --git a/src/store/reducers/auth/auth.js b/src/store/reducers/auth/auth.js
deleted file mode 100644
index 831463d16..000000000
--- a/src/store/reducers/auth/auth.js
+++ /dev/null
@@ -1,11 +0,0 @@
-import { types } from 'k-ramel'
-import split from 'lodash/split'
-
-const defaultData = {
- providers: split(process.env.REACT_APP_AUTH_PROVIDERS, ','),
- authenticated: false,
- uid: undefined,
- error: {},
-}
-
-export default types.object({ defaultData })
diff --git a/src/store/reducers/auth/index.js b/src/store/reducers/auth/index.js
deleted file mode 100644
index ea38ab1b3..000000000
--- a/src/store/reducers/auth/index.js
+++ /dev/null
@@ -1,2 +0,0 @@
-export { default } from './auth'
-export { default as protect } from './protect'
diff --git a/src/store/reducers/auth/protect.js b/src/store/reducers/auth/protect.js
deleted file mode 100644
index 3261f7692..000000000
--- a/src/store/reducers/auth/protect.js
+++ /dev/null
@@ -1,52 +0,0 @@
-/* eslint-disable react/jsx-filename-extension */
-import React from 'react'
-import PropTypes from 'prop-types'
-import { inject } from '@k-ramel/react'
-
-import LoadingIndicator from 'components/loader/loading'
-
-export default (Component) => {
- class ProtectedComponent extends React.Component {
- // eslint-disable-next-line react/static-property-placement
- static propTypes = {
- authenticated: PropTypes.bool.isRequired,
- userDataLoaded: PropTypes.bool.isRequired,
- redirectLogin: PropTypes.func.isRequired,
- }
-
- componentDidMount() {
- this.checkAuth()
- }
-
- componentDidUpdate() {
- this.checkAuth()
- }
-
- checkAuth = () => {
- const { authenticated, redirectLogin } = this.props
- if (!authenticated) {
- redirectLogin()
- }
- }
-
- render() {
- const { authenticated, userDataLoaded, ...rest } = this.props
- if (!authenticated) return null
- if (!userDataLoaded) return
- return
- }
- }
-
- return inject((store) => {
- const auth = store.auth.get()
- const userLoaded = store.data.users.hasKey(auth.uid)
- const orgaLoaded = store.data.organizations.isInitialized()
-
- return {
- ...auth,
- userDataLoaded: userLoaded && orgaLoaded,
- redirectLogin: () =>
- store.dispatch({ type: '@@router/REPLACE_WITH_NEXT_URL', payload: 'login' }),
- }
- })(ProtectedComponent)
-}
diff --git a/src/store/reducers/reducers.js b/src/store/reducers/reducers.js
index c9c83f306..f3f285b80 100644
--- a/src/store/reducers/reducers.js
+++ b/src/store/reducers/reducers.js
@@ -1,9 +1,7 @@
-import auth from './auth'
import data from './data'
import ui from './ui'
export default {
- auth,
data,
ui,
}
diff --git a/src/store/reducers/ui/beta.js b/src/store/reducers/ui/beta.js
deleted file mode 100644
index 1de3c283b..000000000
--- a/src/store/reducers/ui/beta.js
+++ /dev/null
@@ -1,5 +0,0 @@
-import { types } from 'k-ramel'
-
-const defaultData = { error: undefined }
-
-export default types.object({ defaultData })
diff --git a/src/store/reducers/ui/index.js b/src/store/reducers/ui/index.js
index a7664dd43..42e0f6192 100644
--- a/src/store/reducers/ui/index.js
+++ b/src/store/reducers/ui/index.js
@@ -1,13 +1,11 @@
import app from './app'
import speaker from './speaker'
import organizer from './organizer'
-import beta from './beta'
import loaders from './loaders'
export default {
app,
speaker,
organizer,
- beta,
loaders,
}