Skip to content

Commit

Permalink
fix(share): Fix sharers list refresh when extend share
Browse files Browse the repository at this point in the history
  • Loading branch information
franxois committed Jun 7, 2019
1 parent d9e3340 commit 08a3f33
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 20 deletions.
6 changes: 0 additions & 6 deletions client/cypress/integration/1-add-new-note_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,6 @@ describe(`Notes sharing ${seed}`, function() {
cy.contains("Save").click();
cy.contains("Save").should("not.exist");

// Force refresh, status of note should change.
// TODO : remove the need to refresh
cy.wait(2000);
cy.get('[data-test="refresh"]').click();
cy.wait(2000);

// Click on shared button
cy.contains("div.panel-body", encryptedSharedContent, { timeout: 20000 })
.parentsUntil("li")
Expand Down
20 changes: 20 additions & 0 deletions client/src/actions/notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,25 @@ function addNote(Title, Content, sharedIds) {
};
}

function shareNote(note, sharers) {
return async dispatch => {
try {
await notesService.shareNote(note, sharers);
const newNote = await notesService.getNote(note.ID);
dispatch(success(newNote));
} catch (error) {
dispatch(failure(error));
}
dispatch(uiActions.closeModal(uiConstants.ShareNoteModal));
};
function success(note) {
return { type: notesConstants.SHARE_SUCCESS, note };
}
function failure(error) {
return { type: notesConstants.SHARE_FAILURE, error };
}
}

function deleteNote(id) {
return async (dispatch, getState) => {
let del = {
Expand Down Expand Up @@ -108,6 +127,7 @@ function getNotes(group) {

export const noteActions = {
addNote,
shareNote,
deleteNote,
getNotes
};
4 changes: 1 addition & 3 deletions client/src/components/ShareNote.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import ShareSelect from "./ShareSelect";

import { uiConstants } from "../constants";
import { noteActions, uiActions } from "../actions";
import { notesService } from "../services";

class ShareNote extends React.Component {
constructor(props, context) {
Expand Down Expand Up @@ -86,8 +85,7 @@ class ShareNote extends React.Component {
const {
payload: { note }
} = this.props;
await notesService.shareNote(note, this.state.sharingList);
this.props.closeModal(uiConstants.ShareNoteModal);
this.props.shareNote(note, this.state.sharingList);
} catch (e) {
console.log(e);
}
Expand Down
2 changes: 2 additions & 0 deletions client/src/constants/notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export const notesConstants = {
POST_REQUEST: "NOTES_POST_REQUEST",
POST_SUCCESS: "NOTES_POST_SUCCESS",
POST_FAILURE: "NOTES_POST_FAILURE",
SHARE_SUCCESS: "NOTES_SHARE_SUCCESS",
SHARE_FAILURE: "NOTES_SHARE_FAILURE",
DEL_FAILURE: "NOTES_DEL_FAILURE",
GET_USERS_LIST: "NOTES_GET_USERS"
};
2 changes: 2 additions & 0 deletions client/src/reducers/notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ export const notes = (state = [], action) => {
switch (action.type) {
case notesConstants.POST_SUCCESS:
return [...state, action.note];
case notesConstants.SHARE_SUCCESS:
return state.map(n => (n.ID === action.note.ID ? action.note : n));
case notesConstants.DELETE_NOTE:
return state.map(note =>
note.ID === action.id
Expand Down
24 changes: 13 additions & 11 deletions client/src/services/notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,19 @@ export async function shareNote(note, sharingList) {
note.resourceID,
sharingList.map(u => getLogin(u, process.env.REACT_APP_DATAPEPS_APP_ID))
);
await sharingList.map(u => {
const requestOptions = {
method: "POST",
headers: authHeader(false)
};

return fetch(
`${process.env.REACT_APP_API_URL}/auth/share/${note.ID}/${u}`,
requestOptions
);
});
await Promise.all(
sharingList.map(async u => {
const requestOptions = {
method: "POST",
headers: authHeader(false)
};

return await fetch(
`${process.env.REACT_APP_API_URL}/auth/share/${note.ID}/${u}`,
requestOptions
);
})
);
}

async function handleNotesResponse(response) {
Expand Down

0 comments on commit 08a3f33

Please sign in to comment.