index.js 1.96 KB
// import { InviteSignupController } from '/imports/client/views/invite/signup/index'
import _                                  from 'lodash';
import {
         composeWithTracker,
         compose,
         composeAll
       }                                  from 'react-komposer';
import { Loading }                        from '/imports/client/components/Loading';

import { Orgs }                           from '/imports/collections/orgs/index';
import { Users }                          from '/imports/collections/users/index';
import { Staffs }                          from '/imports/collections/staff/index';
import { StaffView }                      from './StaffView';

const meteorTick = (props, onData) => {

  const handles = [
    Meteor.subscribe('users.current'),
    Meteor.subscribe('orgs.current'),
    Meteor.subscribe('users.forMyOrg'),
    Meteor.subscribe('staff.forMyOrg'),
  ];

  if(_.every(handles, (handle) => (handle.ready()) )) {
    const user = Users.current();
    const org = Orgs.current();
    staff = Users.find({"role":"STAFF"}).fetch() ? Users.find({"role":"STAFF"}).fetch() : "";
    console.log(Users.find({"role":"STAFF"}).fetch());
    staffData = Staffs.find().fetch() ? Staffs.find().fetch() : "";
    console.log("staffData");
    console.log(staffData);
    for(var i=0; i< staff.length; i++){
      for(var j=0; j< staffData.length; j++){
        if(staff[i]._id == staffData[j].userId){
          staff[i].type = staffData[j].type;
          staff[i].employeeId = staffData[j].employeeId;
          staff[i].dob = staffData[j].dob;
        }
      }
    }
    onData(null, {
      data: {
        user: user,
        org: org,
        staff: staff
      },
    });
  }

  return () => {
    _.each(handles, (handle) => handle.stop() );
  };
};


const reduxTick = (props, onData) => {
  onData(null, {
    data: {}
  });
};


export const staffViewController = composeAll(
  composeWithTracker(meteorTick, Loading),
  compose(reduxTick, Loading),
)(StaffView);