PR-753737: Se Agregan los Actions de redux y se convierte todo el frontend a typescript.

This commit is contained in:
Alejandro Lembke Barrientos 2022-04-28 18:15:07 +00:00
parent fded666bc3
commit 76272cf3a8
13 changed files with 50 additions and 17 deletions

4
client/custom.d.ts vendored Normal file
View File

@ -0,0 +1,4 @@
declare module "*.svg" {
const content: any;
export default content;
}

View File

@ -1,4 +1,4 @@
import {Workbox} from 'workbox-window'; import { Workbox } from 'workbox-window';
import packageJson from './package.json'; import packageJson from './package.json';
const serviceWorkerRegistration = () => { const serviceWorkerRegistration = () => {

View File

@ -0,0 +1,9 @@
import test, { TTest } from './testAction';
export type TAction = TTest
const actions = {
test
}
export default actions

View File

@ -0,0 +1,25 @@
export enum ActionTypesTest {
ChangeHello = 'CHANGE_HELLO'
}
export interface IChangeHello {
type: ActionTypesTest.ChangeHello
payload: IChangeHelloPayload
}
export interface IChangeHelloPayload {
hello: any | undefined
}
export type TTest = IChangeHello
const changeHello = (payload: string) => ({
type: 'CREATE_USER',
payload
})
const actions = {
changeHello
}
export default actions

View File

@ -5,7 +5,7 @@ import { BrowserRouter as Router } from 'react-router-dom';
// Redux // Redux
import { Provider } from 'react-redux'; import { Provider } from 'react-redux';
import { IInitialState } from './reducers/index'; import { IInitialState } from './reducers/index';
import setStore from './setStore.js'; import setStore from './setStore';
import { config } from '../../config'; import { config } from '../../config';
import './styles/global.sass'; import './styles/global.sass';
@ -61,11 +61,6 @@ hydrateRoot(container,
</Provider> </Provider>
); */ ); */
// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: http://bit.ly/CRA-PWA
//serviceWorker.register();
if((env) && (env === 'production')){ if((env) && (env === 'production')){
serviceWorkerRegistration(); serviceWorkerRegistration();
} }

View File

@ -1,8 +1,9 @@
import { combineReducers } from 'redux'; import { combineReducers } from 'redux';
import testReducer, { ITestReducer } from './testReducer'; import testReducer from './testReducer';
import { IChangeHelloPayload } from '../actions/testAction';
export interface IInitialState { export interface IInitialState {
testReducer?: ITestReducer | undefined testReducer?: IChangeHelloPayload | undefined
} }
const rootReducer = combineReducers({ const rootReducer = combineReducers({

View File

@ -1,2 +1,2 @@
let initialState = {}; const initialState = {};
export default initialState; export default initialState;

View File

@ -1,12 +1,10 @@
export interface ITestReducer { import { TAction } from '../actions';
hello: any | undefined
}
const initialState = { const initialState = {
hello: 'world' hello: 'world'
}; };
const testReducer = (state = initialState, action: { type: any; payload: { hello: any; }; }) => { const testReducer = (state = initialState, action: TAction) => {
switch (action.type){ switch (action.type){
case 'CHANGE_HELLO': { case 'CHANGE_HELLO': {
const newHello = action.payload.hello; const newHello = action.payload.hello;

View File

@ -3,7 +3,8 @@ import { createStore } from 'redux'; //, applyMiddleware
// import { Provider } from 'react-redux'; // import { Provider } from 'react-redux';
import { composeWithDevTools as composeWithDevToolsWeb } from 'redux-devtools-extension'; import { composeWithDevTools as composeWithDevToolsWeb } from 'redux-devtools-extension';
import { config } from '../../config'; import { config } from '../../config';
import reducer from './reducers'; import reducer, { IInitialState } from './reducers';
const { env } = config; const { env } = config;
@ -11,7 +12,7 @@ const composeEnhancers = composeWithDevToolsWeb({
// Specify here name, actionsBlacklist, actionsCreators and other options // Specify here name, actionsBlacklist, actionsCreators and other options
}); });
const setStore = ({ initialState }) => { const setStore = ({ initialState }: { initialState: IInitialState | undefined }) => {
const store = env === 'development' ? createStore( const store = env === 'development' ? createStore(
reducer, reducer,
initialState, initialState,

View File

@ -17,7 +17,7 @@ import { StaticRouter } from 'react-router-dom/server';
import routes from '../routes'; import routes from '../routes';
//Redux //Redux
import { Provider } from 'react-redux'; import { Provider } from 'react-redux';
import setStore from '../frontend/setStore.js'; import setStore from '../frontend/setStore';
import initialState from '../frontend/reducers/initialState'; import initialState from '../frontend/reducers/initialState';
//Get Hashes //Get Hashes
import getHashManifest from './getHashManifest'; import getHashManifest from './getHashManifest';