import { User } from './interfaces' import { get } from 'lodash' import { GoogleScope } from './constants' const root = (state: any) => state.auth export const accessToken = (state: any) => root(state).accessToken.token export const loginStatus = (state: any) => root(state).accessToken.status export const user = (state: any): User => root(state).user export const orgId = (state: any): number => get(user(state), 'orgId') export const userId = (state: any): number => get(user(state), 'id') export const userName = (state: any): string => get(user(state), 'name') export const squareAvatarUrl = (state: any): string => get(user(state), 'avatars.squareCropImage200') const scopes = (state: any) => user(state).scopes export const hasSalesSequences = (state: any) => scopes(state) && scopes(state).indexOf('SALES_SEQUENCES') !== -1 export const isAdmin = (state: any) => scopes(state) && scopes(state).indexOf('org_admin') !== -1 const googleScopes = (state: any) => root(state).googleScopes export const gmailConnected = (state: any) => { return googleScopes(state).includes(GoogleScope.READ) && googleScopes(state).includes(GoogleScope.SEND) }