Compare commits

..

8 Commits

Author SHA1 Message Date
Tudor Stanciu 96c3cf8fbc [1.1.0] 2023-03-19 00:10:34 +02:00
Tudor Stanciu edb5f41a78 Merged PR 76: Added @flare/tuitio-client-react in CDN app
Added @flare/tuitio-client-react in CDN app
2023-03-18 22:08:57 +00:00
Tudor Stanciu a99436e440 Added @flare/tuitio-client-react in CDN app 2023-03-19 00:07:56 +02:00
Tudor Stanciu 33983a785d env 2023-03-18 22:27:48 +02:00
Tudor Stanciu e7fa2ea573 resource-description fix 2023-03-03 19:18:20 +02:00
Tudor Stanciu 32a05db318 @flare/js-utils update 2023-01-30 00:57:47 +02:00
Tudor Stanciu 08dd469be3 set new domain in configs 2022-12-29 22:15:45 +02:00
Tudor Stanciu 6039dda5ce dockerfile: node:12-slim => node:14-slim 2022-12-19 01:30:02 +02:00
24 changed files with 3392 additions and 3816 deletions

5
.env
View File

@ -1,5 +1,6 @@
REACT_APP_IDENTITY_AUTHENTICATION_URL=https://toodle.ddns.net/identity-server-api/identity/authenticate?UserName={username}&Password={password} REACT_APP_TUITIO_URL=https://lab.code-rove.com/tuitio
REACT_APP_ENABLE_TEMPLATE_CONTENT=True REACT_APP_ENABLE_TEMPLATE_CONTENT=True
REACT_APP_CDN_URL=http://localhost:5050 #REACT_APP_CDN_URL=http://localhost:5050
REACT_APP_CDN_URL=https://lab.code-rove.com/cdn
#PUBLIC_URL=/cdn-admin/ #PUBLIC_URL=/cdn-admin/

View File

@ -1,4 +1,4 @@
PUBLIC_URL=/cdn-admin/ PUBLIC_URL=/cdn-admin/
REACT_APP_IDENTITY_AUTHENTICATION_URL=https://toodle.ddns.net/identity-server-api/identity/authenticate?UserName={username}&Password={password} REACT_APP_TUITIO_URL=https://lab.code-rove.com/tuitio
REACT_APP_ENABLE_TEMPLATE_CONTENT=False REACT_APP_ENABLE_TEMPLATE_CONTENT=False
REACT_APP_CDN_URL=https://toodle.ddns.net/cdn REACT_APP_CDN_URL=https://lab.code-rove.com/cdn

2
.npmrc
View File

@ -1 +1 @@
@flare:registry=https://toodle.ddns.net/public-node-registry @flare:registry=https://lab.code-rove.com/public-node-registry

View File

@ -4,7 +4,7 @@ Built with [React](https://facebook.github.io/react/), [Material-UI](https://mat
**This version uses React 16.14.0, React Router v5, MaterialUI v4, built with React Hooks and React Context (No Redux)** **This version uses React 16.14.0, React Router v5, MaterialUI v4, built with React Hooks and React Context (No Redux)**
[View Demo](https://toodle.ddns.net/cdn-admin/) | [Download](https://toodle.ddns.net/gitea/tudor/cdn-frontend) | [More projects](https://toodle.ddns.net/heimdall) | [Support forum](https://toodle.ddns.net/forum) [View Demo](https://lab.code-rove.com/cdn-admin/) | [Download](https://lab.code-rove.com/gitea/tudor/cdn-frontend) | [More projects](https://lab.code-rove.com/heimdall) | [Support forum](https://lab.code-rove.com/forum)
[![image](https://user-images.githubusercontent.com/24964748/55800639-df780300-5adc-11e9-84b7-7c2437088516.png)](https://flatlogic.com/admin-dashboards/react-material-admin/demo) [![image](https://user-images.githubusercontent.com/24964748/55800639-df780300-5adc-11e9-84b7-7c2437088516.png)](https://flatlogic.com/admin-dashboards/react-material-admin/demo)

View File

@ -1,5 +1,5 @@
# build environment # build environment
FROM node:12-slim as builder FROM node:14-slim as builder
WORKDIR /app WORKDIR /app
COPY .npmrc .npmrc COPY .npmrc .npmrc
@ -11,7 +11,7 @@ COPY . ./
RUN npm run build RUN npm run build
# production environment # production environment
FROM node:12-slim FROM node:14-slim
RUN printf '\n\n- Copy application files\n' RUN printf '\n\n- Copy application files\n'
ARG APP_SUBFOLDER=cdn-admin ARG APP_SUBFOLDER=cdn-admin
@ -22,6 +22,11 @@ COPY --from=builder /app/build/index.html ./application/
#install static server #install static server
RUN npm install -g serve RUN npm install -g serve
# environment variables
ENV AUTHOR="Tudor Stanciu"
ARG APP_VERSION=0.0.0
ENV APP_VERSION=${APP_VERSION}
#set workdir to root #set workdir to root
WORKDIR / WORKDIR /

6735
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,15 +1,15 @@
{ {
"name": "cdn-admin", "name": "cdn-admin",
"version": "1.0.0", "version": "1.1.0",
"description": "CDN administration application", "description": "CDN administration application",
"author": { "author": {
"name": "Tudor Stanciu", "name": "Tudor Stanciu",
"email": "tudor.stanciu94@gmail.com", "email": "tudor.stanciu94@gmail.com",
"url": "https://toodle.ddns.net/tsp" "url": "https://lab.code-rove.com/tsp"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://toodle.ddns.net/gitea/tudor/cdn-frontend" "url": "https://lab.code-rove.com/gitea/tudor/cdn-frontend"
}, },
"private": true, "private": true,
"homepage": "./", "homepage": "./",
@ -19,7 +19,8 @@
"node-fetch": "^2.6.1" "node-fetch": "^2.6.1"
}, },
"dependencies": { "dependencies": {
"@flare/js-utils": "^1.0.0", "@flare/js-utils": "^1.0.3",
"@flare/tuitio-client-react": "^1.1.1",
"@material-ui/core": "^4.11.3", "@material-ui/core": "^4.11.3",
"@material-ui/icons": "^4.11.2", "@material-ui/icons": "^4.11.2",
"@material-ui/lab": "^4.0.0-alpha.60", "@material-ui/lab": "^4.0.0-alpha.60",
@ -28,7 +29,7 @@
"@mdi/react": "^1.4.0", "@mdi/react": "^1.4.0",
"@babel/eslint-parser": "^7.16.5", "@babel/eslint-parser": "^7.16.5",
"apexcharts": "^3.24.0", "apexcharts": "^3.24.0",
"axios": "^0.19.2", "axios": "^1.3.4",
"classnames": "^2.2.6", "classnames": "^2.2.6",
"font-awesome": "^4.7.0", "font-awesome": "^4.7.0",
"i18next": "^19.4.4", "i18next": "^19.4.4",

View File

@ -8,21 +8,10 @@ import Layout from "./Layout/Layout";
import Error from "../pages/error"; import Error from "../pages/error";
import Login from "../pages/login"; import Login from "../pages/login";
import ServerNotAvailable from "../features/server/availability/components/ServerNotAvailable"; import ServerNotAvailable from "../features/server/availability/components/ServerNotAvailable";
import { useTuitioToken } from "@flare/tuitio-client-react";
// context
import { useUserState } from "../contexts/UserContext";
import { useToast } from "../contexts/ToastContext";
import { useTranslation } from "react-i18next";
export default function App() { export default function App() {
const { authenticated, messageCode } = useUserState(); const { valid: authenticated } = useTuitioToken();
const { t } = useTranslation();
const { notify } = useToast();
useEffect(() => {
if (!messageCode) return;
notify(t(messageCode), "error");
}, [messageCode, t, notify]);
return ( return (
<BrowserRouter basename={process.env.PUBLIC_URL || ""}> <BrowserRouter basename={process.env.PUBLIC_URL || ""}>

View File

@ -33,7 +33,8 @@ import {
useLayoutDispatch, useLayoutDispatch,
toggleSidebar toggleSidebar
} from "../../contexts/LayoutContext"; } from "../../contexts/LayoutContext";
import { useUserDispatch, signOut } from "../../contexts/UserContext"; import { useTuitioClient } from "@flare/tuitio-client-react";
import { useToast } from "../../hooks";
const messages = [ const messages = [
{ {
@ -94,7 +95,6 @@ export default function Header(props) {
// global // global
var layoutState = useLayoutState(); var layoutState = useLayoutState();
var layoutDispatch = useLayoutDispatch(); var layoutDispatch = useLayoutDispatch();
var userDispatch = useUserDispatch();
// local // local
var [mailMenu, setMailMenu] = useState(null); var [mailMenu, setMailMenu] = useState(null);
@ -104,6 +104,12 @@ export default function Header(props) {
var [profileMenu, setProfileMenu] = useState(null); var [profileMenu, setProfileMenu] = useState(null);
var [isSearchOpen, setSearchOpen] = useState(false); var [isSearchOpen, setSearchOpen] = useState(false);
const { error } = useToast();
const { logout } = useTuitioClient({
onLogoutFailed: (errorMessage) => error(errorMessage),
onLogoutError: (err) => error(err.message)
});
return ( return (
<AppBar position="fixed" className={classes.appBar}> <AppBar position="fixed" className={classes.appBar}>
<Toolbar className={classes.toolbar}> <Toolbar className={classes.toolbar}>
@ -320,7 +326,7 @@ export default function Header(props) {
<Typography <Typography
className={classes.profileMenuLink} className={classes.profileMenuLink}
color="primary" color="primary"
onClick={() => signOut(userDispatch, props.history)} onClick={logout}
> >
Sign Out Sign Out
</Typography> </Typography>

View File

@ -1,7 +1,7 @@
import { makeStyles } from "@material-ui/styles"; import { makeStyles } from "@material-ui/styles";
import { fade } from "@material-ui/core/styles/colorManipulator"; import { alpha } from "@material-ui/core/styles";
export default makeStyles(theme => ({ export default makeStyles((theme) => ({
logotype: { logotype: {
color: "white", color: "white",
marginLeft: theme.spacing(2.5), marginLeft: theme.spacing(2.5),
@ -10,45 +10,45 @@ export default makeStyles(theme => ({
fontSize: 18, fontSize: 18,
whiteSpace: "nowrap", whiteSpace: "nowrap",
[theme.breakpoints.down("xs")]: { [theme.breakpoints.down("xs")]: {
display: "none", display: "none"
}, }
}, },
appBar: { appBar: {
width: "100vw", width: "100vw",
zIndex: theme.zIndex.drawer + 1, zIndex: theme.zIndex.drawer + 1,
transition: theme.transitions.create(["margin"], { transition: theme.transitions.create(["margin"], {
easing: theme.transitions.easing.sharp, easing: theme.transitions.easing.sharp,
duration: theme.transitions.duration.leavingScreen, duration: theme.transitions.duration.leavingScreen
}), })
}, },
toolbar: { toolbar: {
paddingLeft: theme.spacing(2), paddingLeft: theme.spacing(2),
paddingRight: theme.spacing(2), paddingRight: theme.spacing(2)
}, },
hide: { hide: {
display: "none", display: "none"
}, },
grow: { grow: {
flexGrow: 1, flexGrow: 1
}, },
search: { search: {
position: "relative", position: "relative",
borderRadius: 25, borderRadius: 25,
paddingLeft: theme.spacing(2.5), paddingLeft: theme.spacing(2.5),
width: 36, width: 36,
backgroundColor: fade(theme.palette.common.black, 0), backgroundColor: alpha(theme.palette.common.black, 0),
transition: theme.transitions.create(["background-color", "width"]), transition: theme.transitions.create(["background-color", "width"]),
"&:hover": { "&:hover": {
cursor: "pointer", cursor: "pointer",
backgroundColor: fade(theme.palette.common.black, 0.08), backgroundColor: alpha(theme.palette.common.black, 0.08)
}, }
}, },
searchFocused: { searchFocused: {
backgroundColor: fade(theme.palette.common.black, 0.08), backgroundColor: alpha(theme.palette.common.black, 0.08),
width: "100%", width: "100%",
[theme.breakpoints.up("md")]: { [theme.breakpoints.up("md")]: {
width: 250, width: 250
}, }
}, },
searchIcon: { searchIcon: {
width: 36, width: 36,
@ -60,115 +60,115 @@ export default makeStyles(theme => ({
justifyContent: "center", justifyContent: "center",
transition: theme.transitions.create("right"), transition: theme.transitions.create("right"),
"&:hover": { "&:hover": {
cursor: "pointer", cursor: "pointer"
}, }
}, },
searchIconOpened: { searchIconOpened: {
right: theme.spacing(1.25), right: theme.spacing(1.25)
}, },
inputRoot: { inputRoot: {
color: "inherit", color: "inherit",
width: "100%", width: "100%"
}, },
inputInput: { inputInput: {
height: 36, height: 36,
padding: 0, padding: 0,
paddingRight: 36 + theme.spacing(1.25), paddingRight: 36 + theme.spacing(1.25),
width: "100%", width: "100%"
}, },
messageContent: { messageContent: {
display: "flex", display: "flex",
flexDirection: "column", flexDirection: "column"
}, },
headerMenu: { headerMenu: {
marginTop: theme.spacing(7), marginTop: theme.spacing(7)
}, },
headerMenuList: { headerMenuList: {
display: "flex", display: "flex",
flexDirection: "column", flexDirection: "column"
}, },
headerMenuItem: { headerMenuItem: {
"&:hover, &:focus": { "&:hover, &:focus": {
backgroundColor: theme.palette.background.light, backgroundColor: theme.palette.background.light
// color: "white", // color: "white",
}, }
}, },
headerMenuButton: { headerMenuButton: {
marginLeft: theme.spacing(2), marginLeft: theme.spacing(2),
padding: theme.spacing(0.5), padding: theme.spacing(0.5)
}, },
headerMenuButtonSandwich: { headerMenuButtonSandwich: {
marginLeft: 9, marginLeft: 9,
[theme.breakpoints.down("sm")]: { [theme.breakpoints.down("sm")]: {
marginLeft: 0 marginLeft: 0
}, },
padding: theme.spacing(0.5), padding: theme.spacing(0.5)
}, },
headerMenuButtonCollapse: { headerMenuButtonCollapse: {
marginRight: theme.spacing(2), marginRight: theme.spacing(2)
}, },
headerIcon: { headerIcon: {
fontSize: 28, fontSize: 28,
color: "rgba(255, 255, 255, 0.35)", color: "rgba(255, 255, 255, 0.35)"
}, },
headerIconCollapse: { headerIconCollapse: {
color: "white", color: "white"
}, },
profileMenu: { profileMenu: {
minWidth: 265, minWidth: 265
}, },
profileMenuUser: { profileMenuUser: {
display: "flex", display: "flex",
flexDirection: "column", flexDirection: "column",
padding: theme.spacing(2), padding: theme.spacing(2)
}, },
profileMenuItem: { profileMenuItem: {
color: theme.palette.text.hint, color: theme.palette.text.hint
}, },
profileMenuIcon: { profileMenuIcon: {
marginRight: theme.spacing(2), marginRight: theme.spacing(2),
color: theme.palette.text.hint, color: theme.palette.text.hint,
'&:hover': { "&:hover": {
color: theme.palette.primary.main, color: theme.palette.primary.main
} }
}, },
profileMenuLink: { profileMenuLink: {
fontSize: 16, fontSize: 16,
textDecoration: "none", textDecoration: "none",
"&:hover": { "&:hover": {
cursor: "pointer", cursor: "pointer"
}, }
}, },
messageNotification: { messageNotification: {
height: "auto", height: "auto",
display: "flex", display: "flex",
alignItems: "center", alignItems: "center",
"&:hover, &:focus": { "&:hover, &:focus": {
backgroundColor: theme.palette.background.light, backgroundColor: theme.palette.background.light
}, }
}, },
messageNotificationSide: { messageNotificationSide: {
display: "flex", display: "flex",
flexDirection: "column", flexDirection: "column",
alignItems: "center", alignItems: "center",
marginRight: theme.spacing(2), marginRight: theme.spacing(2)
}, },
messageNotificationBodySide: { messageNotificationBodySide: {
alignItems: "flex-start", alignItems: "flex-start",
marginRight: 0, marginRight: 0
}, },
sendMessageButton: { sendMessageButton: {
margin: theme.spacing(4), margin: theme.spacing(4),
marginTop: theme.spacing(2), marginTop: theme.spacing(2),
marginBottom: theme.spacing(2), marginBottom: theme.spacing(2),
textTransform: "none", textTransform: "none"
}, },
sendButtonIcon: { sendButtonIcon: {
marginLeft: theme.spacing(2), marginLeft: theme.spacing(2)
}, },
purchaseBtn: { purchaseBtn: {
[theme.breakpoints.down('sm')]: { [theme.breakpoints.down("sm")]: {
display: 'none' display: "none"
}, },
marginRight: theme.spacing(3) marginRight: theme.spacing(3)
} }

View File

@ -26,7 +26,7 @@ const ContentFooter = () => {
<div> <div>
<Link <Link
color={"primary"} color={"primary"}
href={"https://toodle.ddns.net/heimdall"} href={"https://lab.code-rove.com/heimdall"}
target={"_blank"} target={"_blank"}
className={classes.link} className={classes.link}
> >
@ -34,7 +34,7 @@ const ContentFooter = () => {
</Link> </Link>
<Link <Link
color={"primary"} color={"primary"}
href={"https://toodle.ddns.net/heimdall"} href={"https://lab.code-rove.com/heimdall"}
target={"_blank"} target={"_blank"}
className={classes.link} className={classes.link}
> >
@ -42,7 +42,7 @@ const ContentFooter = () => {
</Link> </Link>
<Link <Link
color={"primary"} color={"primary"}
href={"https://toodle.ddns.net/heimdall"} href={"https://lab.code-rove.com/heimdall"}
target={"_blank"} target={"_blank"}
className={classes.link} className={classes.link}
> >
@ -60,7 +60,7 @@ const ContentFooter = () => {
<Icon path={TwitterIcon} size={1} color="#6E6E6E99" /> <Icon path={TwitterIcon} size={1} color="#6E6E6E99" />
</IconButton> </IconButton>
</Link> </Link>
<Link href={"https://toodle.ddns.net/gitea/"} target={"_blank"}> <Link href={"https://lab.code-rove.com/gitea/"} target={"_blank"}>
<IconButton aria-label="github" style={{ marginRight: -12 }}> <IconButton aria-label="github" style={{ marginRight: -12 }}>
<Icon path={GithubIcon} size={1} color="#6E6E6E99" /> <Icon path={GithubIcon} size={1} color="#6E6E6E99" />
</IconButton> </IconButton>

View File

@ -68,19 +68,19 @@ let menu = [
{ {
id: 9, id: 9,
label: "Menu.Library", label: "Menu.Library",
link: "https://toodle.ddns.net/gitea/tudor/cdn-frontend", link: "https://lab.code-rove.com/gitea/tudor/cdn-frontend",
icon: <LibraryIcon /> icon: <LibraryIcon />
}, },
{ {
id: 10, id: 10,
label: "Menu.Support", label: "Menu.Support",
link: "https://toodle.ddns.net/tsp", link: "https://lab.code-rove.com/tsp",
icon: <SupportIcon /> icon: <SupportIcon />
}, },
{ {
id: 11, id: 11,
label: "Menu.FAQ", label: "Menu.FAQ",
link: "https://toodle.ddns.net/tsp", link: "https://lab.code-rove.com/tsp",
icon: <FAQIcon /> icon: <FAQIcon />
} }
]; ];

View File

@ -61,7 +61,7 @@ export default function Widget({
aria-owns="widget-menu" aria-owns="widget-menu"
aria-haspopup="true" aria-haspopup="true"
onClick={() => setMoreMenuOpen(true)} onClick={() => setMoreMenuOpen(true)}
buttonRef={setMoreButtonRef} ref={setMoreButtonRef}
> >
<MoreIcon /> <MoreIcon />
</IconButton> </IconButton>

View File

@ -37,7 +37,7 @@ const Widget = ({
aria-owns="widget-menu" aria-owns="widget-menu"
aria-haspopup="true" aria-haspopup="true"
onClick={() => props.setMoreMenuOpen(true)} onClick={() => props.setMoreMenuOpen(true)}
buttonRef={props.setMoreButtonRef} ref={props.setMoreButtonRef}
> >
<MoreIcon /> <MoreIcon />
</IconButton> </IconButton>
@ -77,7 +77,7 @@ const Widget = ({
</div> </div>
); );
const styles = theme => ({ const styles = (theme) => ({
widgetWrapper: { widgetWrapper: {
display: "flex", display: "flex",
minHeight: "100%" minHeight: "100%"

View File

@ -1,100 +0,0 @@
import React from "react";
import PropTypes from "prop-types";
import { authenticate, invalidate, validateToken } from "../utils/identity";
var UserStateContext = React.createContext();
var UserDispatchContext = React.createContext();
function userReducer(state, action) {
switch (action.type) {
case "LOGIN_SUCCESS":
return { ...state, ...action.payload, authenticated: true };
case "SIGN_OUT_SUCCESS":
return { ...state, authenticated: false };
case "LOGIN_FAILURE":
return {
...state,
authenticated: false,
messageCode: action.payload?.messageCode
};
default: {
throw new Error(`Unhandled action type: ${action.type}`);
}
}
}
function UserProvider({ children }) {
const { valid, token } = validateToken();
var [state, dispatch] = React.useReducer(userReducer, {
authenticated: valid === true,
token
});
return (
<UserStateContext.Provider value={state}>
<UserDispatchContext.Provider value={dispatch}>
{children}
</UserDispatchContext.Provider>
</UserStateContext.Provider>
);
}
UserProvider.propTypes = {
children: PropTypes.node
};
function useUserState() {
var context = React.useContext(UserStateContext);
if (context === undefined) {
throw new Error("useUserState must be used within a UserProvider");
}
return context;
}
function useUserDispatch() {
var context = React.useContext(UserDispatchContext);
if (context === undefined) {
throw new Error("useUserDispatch must be used within a UserProvider");
}
return context;
}
function setLoginFailed(dispatch, setError, setIsLoading, messageCode) {
dispatch({ type: "LOGIN_FAILURE", payload: { messageCode } });
setError(true);
setIsLoading(false);
}
function loginUser(dispatch, login, password, history, setIsLoading, setError) {
setError(false);
setIsLoading(true);
if (!!login && !!password) {
authenticate(login, password).then((response) => {
if (response.status === "SUCCESS") {
setError(null);
setIsLoading(false);
dispatch({ type: "LOGIN_SUCCESS", payload: { token: response.token } });
} else if (response.status === "BAD_CREDENTIALS") {
setLoginFailed(
dispatch,
setError,
setIsLoading,
"Login.IncorrectCredentials"
);
}
});
history.push("/dashboard");
} else {
setLoginFailed(dispatch, setError, setIsLoading, "Login.EmptyCredentials");
}
}
function signOut(dispatch, history) {
invalidate();
dispatch({ type: "SIGN_OUT_SUCCESS" });
history.push("/login");
}
export { UserProvider, useUserState, useUserDispatch, loginUser, signOut };

View File

@ -136,7 +136,7 @@ const ResourceComponent = ({
<TextField <TextField
fullWidth fullWidth
multiline multiline
rows={12} minRows={2}
id="resource-description" id="resource-description"
label={t("Resource.Description")} label={t("Resource.Description")}
variant="outlined" variant="outlined"

View File

@ -6,7 +6,6 @@ import { LoadingText } from "../../../../components";
import ResourceComponent from "./ResourceComponent"; import ResourceComponent from "./ResourceComponent";
import { makeStyles } from "@material-ui/core/styles"; import { makeStyles } from "@material-ui/core/styles";
import style from "../styles"; import style from "../styles";
import { useToast } from "../../../../hooks";
const useStyles = makeStyles(style); const useStyles = makeStyles(style);
@ -21,7 +20,6 @@ const ResourceContainer = () => {
const params = useParams(); const params = useParams();
const { getResource } = useResourcesApi(); const { getResource } = useResourcesApi();
const { getMimeTypes, getResourceCategories } = useDictionariesApi(); const { getMimeTypes, getResourceCategories } = useDictionariesApi();
const { success } = useToast();
const isNew = useMemo(() => params.id === "new", [params.id]); const isNew = useMemo(() => params.id === "new", [params.id]);

View File

@ -1,15 +1,15 @@
import { useUserState } from "../contexts/UserContext"; import { useTuitioToken } from "@flare/tuitio-client-react";
import { useCallback } from "react"; import { useCallback } from "react";
const useResourceSecurity = () => { const useResourceSecurity = () => {
const { token } = useUserState(); const { token } = useTuitioToken();
const secureUrl = useCallback( const secureUrl = useCallback(
(url) => { (url) => {
const separator = url.includes("?") ? "&" : "?"; const separator = url.includes("?") ? "&" : "?";
const securedUrl = `${url}${separator}token=${token.raw}`; const securedUrl = `${url}${separator}token=${token}`;
return securedUrl; return securedUrl;
}, },
[token.raw] [token]
); );
return { secureUrl }; return { secureUrl };

View File

@ -1,18 +1,18 @@
import React, { Suspense } from "react"; import React, { Suspense } from "react";
import ReactDOM from "react-dom"; import ReactDOM from "react-dom";
import { TuitioProvider } from "@flare/tuitio-client-react";
import { ThemeProvider } from "@material-ui/styles"; import { ThemeProvider } from "@material-ui/styles";
import { CssBaseline } from "@material-ui/core"; import { CssBaseline } from "@material-ui/core";
import Themes from "./themes"; import Themes from "./themes";
import App from "./components/App"; import App from "./components/App";
import * as serviceWorker from "./serviceWorker"; import * as serviceWorker from "./serviceWorker";
import { LayoutProvider } from "./contexts/LayoutContext"; import { LayoutProvider } from "./contexts/LayoutContext";
import { UserProvider } from "./contexts/UserContext";
import { ToastProvider } from "./contexts/ToastContext"; import { ToastProvider } from "./contexts/ToastContext";
import "./utils/i18n"; import "./utils/i18n";
ReactDOM.render( ReactDOM.render(
<LayoutProvider> <LayoutProvider>
<UserProvider> <TuitioProvider tuitioUrl={process.env.REACT_APP_TUITIO_URL}>
<ThemeProvider theme={Themes.default}> <ThemeProvider theme={Themes.default}>
<CssBaseline /> <CssBaseline />
<Suspense fallback={<div>Loading...</div>}> <Suspense fallback={<div>Loading...</div>}>
@ -21,7 +21,7 @@ ReactDOM.render(
</ToastProvider> </ToastProvider>
</Suspense> </Suspense>
</ThemeProvider> </ThemeProvider>
</UserProvider> </TuitioProvider>
</LayoutProvider>, </LayoutProvider>,
document.getElementById("root") document.getElementById("root")
); );

View File

@ -18,23 +18,32 @@ import useStyles from "./styles";
// logo // logo
import logo from "./logo.svg"; import logo from "./logo.svg";
import google from "../../images/google.svg"; import google from "../../images/google.svg";
import { useToast } from "../../hooks";
import { useTuitioClient } from "@flare/tuitio-client-react";
// context function Login() {
import { useUserDispatch, loginUser } from "../../contexts/UserContext"; const classes = useStyles();
const [activeTabId, setActiveTabId] = useState(0);
const [nameValue, setNameValue] = useState("");
const [loginValue, setLoginValue] = useState("");
const [passwordValue, setPasswordValue] = useState("");
const [isLoading, setIsLoading] = useState(false);
const [errorEncountered, setErrorEncountered] = useState(false);
function Login(props) { const { error } = useToast();
var classes = useStyles(); const { login } = useTuitioClient({
onLoginSuccess: () => setIsLoading(false),
onLoginFailed: () => error(t("Login.IncorrectCredentials")),
onLoginError: (err) => {
setErrorEncountered(true);
error(err.message);
}
});
// global const handleLogin = () => {
var userDispatch = useUserDispatch(); setIsLoading(true);
login(loginValue, passwordValue);
// local };
var [isLoading, setIsLoading] = useState(false);
var [error, setError] = useState(null);
var [activeTabId, setActiveTabId] = useState(0);
var [nameValue, setNameValue] = useState("");
var [loginValue, setLoginValue] = useState("");
var [passwordValue, setPasswordValue] = useState("");
return ( return (
<Grid container className={classes.container}> <Grid container className={classes.container}>
@ -68,7 +77,7 @@ function Login(props) {
<Typography className={classes.formDividerWord}>or</Typography> <Typography className={classes.formDividerWord}>or</Typography>
<div className={classes.formDivider} /> <div className={classes.formDivider} />
</div> </div>
<Fade in={error}> <Fade in={errorEncountered}>
<Typography color="secondary" className={classes.errorMessage}> <Typography color="secondary" className={classes.errorMessage}>
Something is wrong with your login or password :( Something is wrong with your login or password :(
</Typography> </Typography>
@ -111,16 +120,7 @@ function Login(props) {
disabled={ disabled={
loginValue.length === 0 || passwordValue.length === 0 loginValue.length === 0 || passwordValue.length === 0
} }
onClick={() => onClick={handleLogin}
loginUser(
userDispatch,
loginValue,
passwordValue,
props.history,
setIsLoading,
setError
)
}
variant="contained" variant="contained"
color="primary" color="primary"
size="large" size="large"
@ -201,16 +201,7 @@ function Login(props) {
<CircularProgress size={26} /> <CircularProgress size={26} />
) : ( ) : (
<Button <Button
onClick={() => onClick={handleLogin}
loginUser(
userDispatch,
loginValue,
passwordValue,
props.history,
setIsLoading,
setError
)
}
disabled={ disabled={
loginValue.length === 0 || loginValue.length === 0 ||
passwordValue.length === 0 || passwordValue.length === 0 ||

View File

@ -1,32 +1,31 @@
import defaultTheme from "./default"; import defaultTheme from "./default";
import { createTheme } from "@material-ui/core/styles";
import { createMuiTheme } from "@material-ui/core";
const overrides = { const overrides = {
typography: { typography: {
h1: { h1: {
fontSize: "3rem", fontSize: "3rem"
}, },
h2: { h2: {
fontSize: "2rem", fontSize: "2rem"
}, },
h3: { h3: {
fontSize: "1.64rem", fontSize: "1.64rem"
}, },
h4: { h4: {
fontSize: "1.5rem", fontSize: "1.5rem"
}, },
h5: { h5: {
fontSize: "1.285rem", fontSize: "1.285rem"
}, },
h6: { h6: {
fontSize: "1.142rem", fontSize: "1.142rem"
}, }
}, }
}; };
const themes = { const themes = {
default: createMuiTheme({ ...defaultTheme, ...overrides }), default: createTheme({ ...defaultTheme, ...overrides })
}; };
export default themes; export default themes;

View File

@ -1,15 +1,14 @@
import axios from "axios"; import axios from "axios";
import i18next from "i18next"; import i18next from "i18next";
import { getItem } from "./localStorage"; import { fetch as fetchTuitioData } from "@flare/tuitio-client";
import { storageKeys } from "./identity";
function getHeaders() { function getHeaders() {
const token = getItem(storageKeys.TOKEN); const { token } = fetchTuitioData();
const language = i18next.language; const language = i18next.language;
return { return {
"Content-Type": "application/json", "Content-Type": "application/json",
Authorization: `Basic ${token.raw}`, Authorization: `Tuitio ${token}`,
"Accept-Language": `${language}` "Accept-Language": `${language}`
}; };
} }

View File

@ -1,50 +0,0 @@
import { request } from "./axios";
import { setItem, getItem, removeItem } from "./localStorage";
const storageKeys = {
TOKEN: "AUTHORIZATION_TOKEN",
USER: "USER_NAME"
};
const authenticate = async (userName, password) => {
const urlTemplate = process.env.REACT_APP_IDENTITY_AUTHENTICATION_URL;
const url = urlTemplate
.replace("{username}", userName)
.replace("{password}", password);
const options = {
method: "post"
};
const response = await request(url, options);
if (response.status === "SUCCESS") {
setItem(storageKeys.TOKEN, response.token);
setItem(storageKeys.USER, userName);
}
return response;
};
const invalidate = () => {
const token = getItem(storageKeys.TOKEN);
if (token) {
removeItem(storageKeys.TOKEN);
removeItem(storageKeys.USER);
}
};
const validateToken = () => {
let token = getItem(storageKeys.TOKEN);
if (!token) {
return { valid: false };
}
const valid = new Date(token.validUntil) >= new Date();
if (!valid) {
invalidate();
token = null;
}
return { valid, token };
};
export { storageKeys, authenticate, invalidate, validateToken };

View File

@ -1,38 +0,0 @@
import { typeValidator } from "@flare/js-utils";
const setItem = (key, value) => {
const { isArray, isObject } = typeValidator;
let valueToStore = value;
if (isArray(value) || isObject(value)) {
valueToStore = JSON.stringify(value);
}
window.localStorage.setItem(key, valueToStore);
};
const getItem = (key) => {
var value = window.localStorage.getItem(key);
const { isJson } = typeValidator;
var { data, success } = isJson(value);
if (success) {
return data;
} else {
return value;
}
};
const removeItem = (key) => {
window.localStorage.removeItem(key);
};
const clear = () => {
window.localStorage.clear();
};
const key = (index) => {
var keyName = window.localStorage.key(index);
return keyName;
};
export { setItem, getItem, removeItem, clear, key };