HackYourFuture-CPH / simply-name.it

Final Project for Class17
MIT License
3 stars 1 forks source link

Fix: addMember page: firebase user and automatic owner addition #251

Closed shpomp closed 3 years ago

shpomp commented 3 years ago

Description

AddMembers page now hides the user from UI when adding members, but is designed in a way to add it automatically as the 'owner' type of member to the board.

Fixes #250

npm run dev and check http://localhost:3000/boards/new-board - add member

Checklist

senner007 commented 3 years ago

@shpomp How is the owner added here?

shpomp commented 3 years ago

@shpomp How is the owner added here?

The owner is used as the initial state of the members array, that Diny uses to loop through with the addMember endpoint:

// ...
import { useUser } from '../../firebase/UserContext';

export default function CreateBoard() {
  const { user } = useUser();
  const userId = user[0].id;
  const [members, setMembers] = useState([userId]);
  const addMember = (id) => {
    setMembers([...members, id]);
  };
// ....

The owner (user) is also hidden from the UI now, which is more logical:

// ...
const renderUser = (user) => {
    if (user.id !== userId) {
// ....

So the members array is now always starting with members[0] = owner, where endpoint takes care of this, as userId === memberId