Browse Source

add combo list

tags/Baseline_30082024_FRONTEND_UAT
leoho2fi 1 year ago
parent
commit
58b730b533
2 changed files with 61 additions and 0 deletions
  1. +28
    -0
      src/app/utils/ComboConst.js
  2. +33
    -0
      src/auth/utils.js

+ 28
- 0
src/app/utils/ComboConst.js View File

@@ -0,0 +1,28 @@
import { useIntl } from "react-intl";
const intl = useIntl()

export const TEAM_COMBO = [
{ id: 1, key: 1, label: 'AAA', value: "AAA" },
{ id: 2, key: 2, label: 'BBB', value: "BBB" },
{ id: 3, key: 3, label: 'CCC', value: "CCC" },
];

export const CLIENT_COMBO = [
{ id: 1, key: 1, label: 'Cust A', value: "Cust A" },
{ id: 2, key: 2, label: 'Cust B', value: "Cust B" },
{ id: 3, key: 3, label: 'Cust C', value: "Cust C" },
];

export function LOCALE_COMBO() {
return ([
{id: 1,label: intl.formatMessage({ id: "en" }),value: "en",},
{id: 2,label: intl.formatMessage({ id: "zh-HK" }),value: "zh-HK",},
{id: 3,label: intl.formatMessage({ id: "zh-CN" }),value: "zh-CN",},
])
}
export function OVERCONSUMPTION_COMBO() {
return ([
{id: 1,label: intl.formatMessage({ id: "Overconsumption" }),value: "Overconsumption",},
{id: 2,label: intl.formatMessage({ id: "Potential Overconsumption" }),value: "Potential Overconsumption",},
])
}

+ 33
- 0
src/auth/utils.js View File

@@ -0,0 +1,33 @@
import useJwt from 'auth/jwt/coreUseJwt'

/**
* Return if user is logged in
* This is completely up to you and how you want to store the token in your frontend application
* e.g. If you are using cookies to store the application please update this function
*/
// eslint-disable-next-line arrow-body-style
export const hostname = process.env.REACT_APP_BACKEND_HOST
const hostPort = process.env.REACT_APP_BACKEND_PORT
export const hostPath = `${process.env.REACT_APP_BACKEND_PROTOCOL}://${hostname}:${hostPort}`
export const apiPath = `${hostPath}/api`

export const isUserLoggedIn = () => {
return localStorage.getItem('userData') && localStorage.getItem(useJwt.jwtConfig.storageTokenKeyName)
}

export const getUserData = () => JSON.parse(localStorage.getItem('userData'))

/**
* This function is used for demo purpose route navigation
* In real app you won't need this function because your app will navigate to same route for each users regardless of ability
* Please note role field is just for showing purpose it's not used by anything in frontend
* We are checking role just for ease
* NOTE: If you have different pages to navigate based on user ability then this function can be useful. However, you need to update it.
* @param {String} userRole Role of user
*/
export const getHomeRouteForLoggedInUser = userRole => {
if (userRole === 'admin') return '/'
if (userRole === 'user') return '/'
if (userRole === 'client') return {name: 'access-control'}
return {name: 'auth-login'}
}

Loading…
Cancel
Save