Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create edit training page #39

Open
brauliodiez opened this issue Dec 2, 2016 · 1 comment
Open

Create edit training page #39

brauliodiez opened this issue Dec 2, 2016 · 1 comment

Comments

@brauliodiez
Copy link
Member

brauliodiez commented Dec 2, 2016

Implement Edit Trainin Page from Admin module.

Wiki: Admin Edit Training

Page View

  • Right now there dummy page under src/pages/admin/training/edit.

Steps:

  • Create a fork.

  • Start by the simple case, just edit the training data, then move on to next scenarios.

  • Create new branch called feature/<issue_number>_Create_Edit_Training_Page (where issue_number is the id of this issue given by Github).

    • Good news: We have alreay a training entity under model.
    • rest-api/trainig.ts: We need here a method to extract a training given an Id:

Pseudocode proposal:

  getTrainingById(id: number): Promise<TrainingEntity> {
    const training = this.trainingData.find(tr => tr.id === id);
    return Promise.resolve(training);
  }
  • Let's go now start bottom up:
    • Let's create an action file (please follow TDD on this):

./src/pages/admin/training/edit/actions/trainingFetchRequest
(pseudocode)

import { adminActionEnums } from '../../../../../common/actionEnums/admin'
import { TrainingEntity} from '../../../../../model/training'
import { trainingApi } from '../../../../../rest-api'

export const trainingFetchRequestStarted = (trainingId) => {
  return function(dispatcher) {
    const promise = trainigApi.getTrainingById(trainingId);

    promise.then(
      data => dispatcher(trainingFetchRequestCompleted(data))
    )

    return promise;
  }
}

export const trainingFetchRequestCompleted = (training: TrainingEntity) => ({
    type: adminActionEnums.GET_TRAINING_REQUEST_COMPLETED,
    payload: training
});
  • Now it's time to jump into the reduces side, we are going to create a new reducer (please follow TDD on this)

./src/reducers/adminTrainings.ts

import { Action } from 'redux'
import { TrainingEntity } from '../model/trainingEntity'
import { adminActionEnums} from '../common/actionEnums/admin'


export class AdminTrainingState {
  training :  TrainingEntity;

  public constructor() {
    this.training = new Training();
  }
}

export const adminTrainingReducer = (state : AdminTrainingState = new AdminTrainingState(), action) => {
  switch(action.type) {
    case adminActionEnums.GET_TRAINING_REQUEST_COMPLETED:
      return handleGetTrainingRequestCompleted(state, action.payload);
  }

  return state;
}

const handleGetTrainingRequestCompleted=
  (state : AdminTrainingState, payload : TrainingEntity) => {
      return {
         ...state,
         training: payload
      };
}
  • We will add it to the combinereducers:

./src/reducers/index.ts

import { combineReducers } from 'redux';
import { AdminStudentState, adminStudentReducer} from './adminStudent'
import { AdminTraningState, adminTrainingReducer} from './adminTraining'

export interface IAppState {
  adminStudent : AdminStudentState,
 adminTrainingState: AdminTraningState
}

export const reducers = combineReducers<IAppState>({
  adminStudent: adminStudentReducer,
  adminTrainingReducer: adminTrainingReducer
});

Next steps:

  • Implement first tab. only UI for now.

  • Implement tabs component using react-toolbox.

  • Add form validations.

  • Implement first tab with functionality (Save).

  • Implement second tab.

  • Important: Follow this work flow

@nasdan
Copy link
Member

nasdan commented Jul 28, 2017

Assigned to @baltika9

@nasdan nasdan removed their assignment Jul 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants