Как отрендерить коллекцию firestoreConnect на основе условия? - PullRequest
0 голосов
/ 06 мая 2020

Я хочу отобразить firestoreConnect при таком условии, но возникает ошибка:

if(props.profile.role=="Admin"){
  { collection: "orders", where: [["userId", "==", props.uid]] },


}else {
  { collection: "orders"},

}

Это потому, что я хочу показать все документы в коллекции, если роль пользователя - Admin. Если роль пользователя не админ, показывать только его заказы. Приведенный ниже код - это мой mapStateToProps и состоит из компонента. Они работают, но моя проблема в том, как добавить условие if-else

const mapStateToProps = (state) => {
      return {
        uid: state.firebase.auth.uid,
        projects: state.firestore.ordered.projects,
        notifications: state.firestore.ordered.notifications,
        users: state.firestore.ordered.users,
        auth: state.firebase.auth,
        orders: state.firestore.ordered.orders,
        profile: state.firebase.profile,
        // orders: state.firestore.ordered.orders.filter(
        //   (orders) => userid === props.auth.uid
        // ),
      };
    };

    export default compose(
      connect(mapStateToProps),

      firestoreConnect((props) => [
        { collection: "orders", where: [["userId", "==", props.uid]] },
        { collection: "notifications", limit: 5, orderBy: ["time", "desc"] },
        { collection: "users" },
      ])
    )(AdminPanel);
...