openreplay/frontend/app/duck/user.js
Delirium 1326bb2eae
feat spot: init commit for extension (#2452)
* feat spot: init commit for extension

* nvmrc

* fix login flow

* Spots Gridview Updates (#2422)

* feat ui: login flow for spot extension

* spot list, store and service created

* some fixing for header

* start work on single spot

* spot player start

* header for player, comments, icons, etc

* split stuff into compoennts, create player state manager

* player controls, activity panel etc etc

* comments, empty page, rename and stuff

* interval buttons etc

* access modal

* pubkey support

* fix tooltip

* limit 10 -> 9

* hls lib instead of videojs

* some warnings

* fix date display for exp

* change public links

* display more client data

* fix cleaning, init comment

* map network to replay player network ev

* stream support, console panel, close panels on X

* fixing streaming, destroy on leave

* fix autoplay

* show notification on spot login

* fix spot login

* backup player added, fix audio issue

* show thumbnail when no video, add spot roles

* add poster thumbnail

* some fixes to video check

* fix events jump

* fix play btn

* try catch over pubkey

* feat ui: login flow for spot extension

* spot list, store and service created

* some fixing for header

* start work on single spot

* spot player start

* header for player, comments, icons, etc

* split stuff into compoennts, create player state manager

* player controls, activity panel etc etc

* comments, empty page, rename and stuff

* interval buttons etc

* access modal

* pubkey support

* fix tooltip

* limit 10 -> 9

* hls lib instead of videojs

* some warnings

* fix date display for exp

* change public links

* display more client data

* fix cleaning, init comment

* map network to replay player network ev

* stream support, console panel, close panels on X

* fixing streaming, destroy on leave

* fix autoplay

* show notification on spot login

* fix spot login

* backup player added, fix audio issue

* show thumbnail when no video, add spot roles

* add poster thumbnail

* some fixes to video check

* fix events jump

* fix play btn

* try catch over pubkey

* icons

* Various updates

* Update SVG.tsx

* Update SideMenu.tsx

* SpotList & Menu updates

* feat ui: login flow for spot extension

* spot list, store and service created

* some fixing for header

* start work on single spot

* spot player start

* header for player, comments, icons, etc

* split stuff into compoennts, create player state manager

* player controls, activity panel etc etc

* comments, empty page, rename and stuff

* interval buttons etc

* access modal

* pubkey support

* fix tooltip

* limit 10 -> 9

* hls lib instead of videojs

* some warnings

* fix date display for exp

* change public links

* display more client data

* fix cleaning, init comment

* map network to replay player network ev

* stream support, console panel, close panels on X

* fixing streaming, destroy on leave

* fix autoplay

* show notification on spot login

* fix spot login

* backup player added, fix audio issue

* show thumbnail when no video, add spot roles

* add poster thumbnail

* some fixes to video check

* fix events jump

* fix play btn

* try catch over pubkey

* icons

* spot login pinging

* Spot List & Player Updates

* move spot login flow to login comp, use separate spot login path for unique jwt

* invalidate spot jwt on logout

* add visual data on page load event

* typo fix

* Spot Listing improvements post review.

* Update SpotListItem.tsx

* Improved Spot List and Item Details

* Minor improvements

* More improvements

* Public player header improvements

* Moved formatExpirationTime to utils

* fixes after merge

---------

Co-authored-by: nick-delirium <nikita@openreplay.com>

* set sso link to <a>?

* some small perf fixes

* login duck reformat...

* Update frontend.yaml

* add observer to spot list header

* split list header

* update spotjwt param in router

* fix toast in router

* fix async fetch, move ctx

* capture space btn ev

* fix header link

* public sharing error msg

* fix err msg for unsuccessful rec start

* fix list alignment

* Caching assets. Finally!!!

* fix typing in comment field

* add pubkey to comments, fix console jump btn

* no content comp

* change refresh token logic

* move thumbnail ts

* move thumbnail ts

* fix tab change

* switch up toggler

* early exit if no jwt present

* regenerate icons

* fix location str

* fix ctx

* change thumnail res, return autoplay for video player

* parse links in console rows, fix injected method parse?

* remove ts from js

* fix console parsing order?

* fixes for autoplay

* xray for spot player

* move to spot list after login;
esc to cancel;
fix signup link;
move ux commit

* kb sc for skipping; xray for spot ext

* track aborted requests

* tooltip for readability

* fixing empty state

* New blank state + various minor improvements (#2471)

* New blank state + various minor improvements

* apres merge

---------

Co-authored-by: nick-delirium <nikita@openreplay.com>

* rm temp v

* init or card

* empty state debug

* empty state debug

* empty state debug

* fix initor img

* spotonly scope support

* Improved Spot dead-end pages (#2475)

* Improved Spot dead-end pages

* Initiate OpenReplay Setup and some more

* get scope changes

* fix crash

* scope upgrade/downgrade

* scope setup flow

* ping for backend

* upgrade wxt deps

* cancel ping int on expiration

* check rec status

* fix ping

* check video processing state

* check video processing state

* fix xray close, network highlight, fcp rounding

* update wxt, move open spot stuff to settings

* fix some history issues

* fix spot login flow

* fix spot login again

* fix spot login again

* don't send two requests

* limit messages for logged users

* limit messages for logged users

* fix public ignore

* microphone stuff

* microphone stuff

* Various improvements (#2509)

* Various improvements

- Updated icons in mic settings
- Included prefix in Spot title
- Save recording notification has been updated
- Other minor UI improvements

* Inline declaration of spot name field, and settings UI

* str f

---------

Co-authored-by: nick-delirium <nikita@openreplay.com>

* UI changes in player header, spot list (#2510)

* Added UI elements in player page

- Badge with counts for comments
- Download and Delete dropdown in player
- Spot selection -- UI improvement

* Minor copy updates

* completing changes

---------

Co-authored-by: nick-delirium <nikita@openreplay.com>

* rm cmt

* fix cellmeasurer

* thumbnail dur

* fix download

* Minor fixes (#2512)

- Spot delete confirmation
- Spot comments UI update
- Minor copy updates

* limit number of notif messages

* add spot title to doc title, add cache groups for webpack

* drop mic controls from recording popup view

* fix for webpack compress

* fix for auto mic pickup

* change status banners

* move svgs around, remove undefined check

* refactor svgs

* fix timetable scaling

* fix error popup

* self contain css

* pre-select spot on spot onboarding

---------

Co-authored-by: Sudheer Salavadi <connect.uxmaster@gmail.com>
Co-authored-by: Rajesh Rajendran <rjshrjndrn@users.noreply.github.com>
2024-08-29 13:35:58 +02:00

281 lines
7.6 KiB
JavaScript

import Account from 'Types/account';
import Client from 'Types/client';
import { List, Map } from 'immutable';
import { deleteCookie } from 'App/utils';
import withRequestState, { RequestTypes } from './requestStateCreator';
export const LOGIN = new RequestTypes('user/LOGIN');
export const SIGNUP = new RequestTypes('user/SIGNUP');
export const RESET_PASSWORD = new RequestTypes('user/RESET_PASSWORD');
export const REQUEST_RESET_PASSWORD = new RequestTypes(
'user/REQUEST_RESET_PASSWORD'
);
export const FETCH_ACCOUNT = new RequestTypes('user/FETCH_ACCOUNT');
const FETCH_TENANTS = new RequestTypes('user/FETCH_TENANTS');
const UPDATE_ACCOUNT = new RequestTypes('user/UPDATE_ACCOUNT');
const RESEND_EMAIL_VERIFICATION = new RequestTypes(
'user/RESEND_EMAIL_VERIFICATION'
);
const FETCH_CLIENT = new RequestTypes('user/FETCH_CLIENT');
export const UPDATE_PASSWORD = new RequestTypes('user/UPDATE_PASSWORD');
const PUT_CLIENT = new RequestTypes('user/PUT_CLIENT');
const RESET_ERRORS = 'user/RESET_ERRORS';
const PUSH_NEW_SITE = 'user/PUSH_NEW_SITE';
const SET_ONBOARDING = 'user/SET_ONBOARDING';
const UPDATE_ACCOUNT_MODULE = 'user/UPDATE_ACCOUNT_MODULE';
const UPGRADE_ACCOUNT_SCOPE = new RequestTypes('user/UPGRADE_ACCOUNT_SCOPE');
const DOWNGRADE_ACCOUNT_SCOPE = new RequestTypes('user/DOWNGRADE_ACCOUNT_SCOPE');
export const initialState = Map({
account: Account(),
siteId: null,
passwordRequestError: false,
passwordErrors: List(),
tenants: [],
authDetails: {},
onboarding: false,
sites: List(),
jwt: null,
spotJwt: null,
errors: List(),
loginRequest: {
loading: false,
errors: [],
},
scope: null,
scopeSetup: false,
});
const setClient = (state, data) => {
const client = Client(data);
return state.set('client', client);
};
export const UPDATE_JWT = 'jwt/UPDATE';
export const DELETE = new RequestTypes('jwt/DELETE');
export function setJwt(data) {
return {
type: UPDATE_JWT,
data,
};
}
export const getScope = (state) => state.getIn(['user', 'scope']);
const reducer = (state = initialState, action = {}) => {
switch (action.type) {
case RESET_ERRORS:
return state.set('requestResetPassowrd', List());
case UPDATE_JWT:
return state
.set('jwt', action.data.jwt)
.set('spotJwt', action.data.spotJwt);
case LOGIN.REQUEST:
return state.set('loginRequest', { loading: true, errors: [] });
case RESET_PASSWORD.SUCCESS:
case LOGIN.SUCCESS:
return state
.set('account', Account({ ...action.data.data.user }))
.set('spotJwt', action.data.spotJwt)
.set('scope', action.data.data.scope)
.set('loginRequest', { loading: false, errors: [] });
case UPDATE_PASSWORD.REQUEST:
case UPDATE_PASSWORD.SUCCESS:
return state.set('passwordErrors', List());
case SIGNUP.SUCCESS:
return state
.set('account', Account(action.data.user))
.set('scope', action.data.scope)
.set('scopeSetup', true);
case UPGRADE_ACCOUNT_SCOPE.SUCCESS:
return state
.set('scope', 'full')
.set('scopeSetup', false)
.set('onboarding', true)
case DOWNGRADE_ACCOUNT_SCOPE.SUCCESS:
return state
.set('scope', 'spot')
.set('scopeSetup', false)
case REQUEST_RESET_PASSWORD.SUCCESS:
break;
case UPDATE_ACCOUNT.SUCCESS:
case FETCH_ACCOUNT.SUCCESS:
return state
.set('account', Account(action.data))
.set('scope', action.data.scope)
.set('passwordErrors', List());
case FETCH_TENANTS.SUCCESS:
return state.set('authDetails', action.data);
case UPDATE_PASSWORD.FAILURE:
return state.set('passwordErrors', List(action.errors));
case LOGIN.FAILURE:
console.log('login failed', action);
deleteCookie('jwt', '/', 'openreplay.com');
return state.set('loginRequest', {
loading: false,
errors: action.errors,
});
case FETCH_ACCOUNT.FAILURE:
case DELETE.SUCCESS:
case DELETE.FAILURE:
deleteCookie('jwt', '/', 'openreplay.com');
return initialState;
case PUT_CLIENT.REQUEST:
return state.mergeIn(['account'], action.params);
case FETCH_CLIENT.SUCCESS:
return setClient(state, action.data);
case PUSH_NEW_SITE:
return state.updateIn(['site', 'list'], (list) =>
list.push(action.newSite)
);
case SET_ONBOARDING:
return state.set('onboarding', action.state);
case UPDATE_ACCOUNT_MODULE:
return state.updateIn(['account', 'settings', 'modules'], (modules) => {
if (modules.includes(action.moduleKey)) {
return modules.filter((module) => module !== action.moduleKey);
} else {
return modules.concat(action.moduleKey);
}
});
}
return state;
};
export default withRequestState(
{
signupRequest: SIGNUP,
updatePasswordRequest: UPDATE_PASSWORD,
requestResetPassowrd: REQUEST_RESET_PASSWORD,
resetPassword: RESET_PASSWORD,
fetchUserInfoRequest: [FETCH_ACCOUNT, FETCH_CLIENT, FETCH_TENANTS],
putClientRequest: PUT_CLIENT,
updateAccountRequest: UPDATE_ACCOUNT,
},
reducer
);
export const upgradeScope = () => ({
types: UPGRADE_ACCOUNT_SCOPE.toArray(),
call: (client) => client.post('/account/scope', { scope: 'full' }),
})
export const downgradeScope = () => ({
types: DOWNGRADE_ACCOUNT_SCOPE.toArray(),
call: (client) => client.post('/account/scope', { scope: 'spot' }),
})
export const login = (params) => ({
types: LOGIN.toArray(),
call: (client) => client.post('/login', params),
});
export const loadingLogin = () => ({
type: LOGIN.REQUEST,
});
export const loginSuccess = (data) => ({
type: LOGIN.SUCCESS,
data,
});
export const loginFailure = (errors) => ({
type: LOGIN.FAILURE,
errors,
});
export const signup = (params) => (dispatch) =>
dispatch({
types: SIGNUP.toArray(),
call: (client) => client.post('/signup', params),
});
export const resetPassword = (params) => (dispatch) =>
dispatch({
types: RESET_PASSWORD.toArray(),
call: (client) => client.post('/password/reset', params),
});
export const requestResetPassword = (params) => (dispatch) =>
dispatch({
types: REQUEST_RESET_PASSWORD.toArray(),
call: (client) => client.post('/password/reset-link', params),
});
export const updatePassword = (params) => (dispatch) =>
dispatch({
types: UPDATE_PASSWORD.toArray(),
call: (client) => client.post('/account/password', params),
});
export function fetchTenants() {
return {
types: FETCH_TENANTS.toArray(),
call: (client) => client.get('/signup'),
};
}
export const fetchUserInfo = () => ({
types: FETCH_ACCOUNT.toArray(),
call: (client) => client.get('/account'),
});
export function logout() {
return {
types: DELETE.toArray(),
call: (client) => client.get('/logout'),
};
}
export function updateClient(params) {
return {
types: PUT_CLIENT.toArray(),
call: (client) => client.post('/account', params),
params,
};
}
export function updateAccount(params) {
return {
types: UPDATE_ACCOUNT.toArray(),
call: (client) => client.post('/account', params),
};
}
export function resendEmailVerification(email) {
return {
types: RESEND_EMAIL_VERIFICATION.toArray(),
call: (client) => client.post('/re-validate', { email }),
};
}
export function pushNewSite(newSite) {
return {
type: PUSH_NEW_SITE,
newSite,
};
}
export function setOnboarding(state = false) {
return {
type: SET_ONBOARDING,
state,
};
}
export function resetErrors() {
return {
type: RESET_ERRORS,
};
}
export function updateModule(moduleKey) {
return {
type: UPDATE_ACCOUNT_MODULE,
moduleKey,
};
}