From eb01334b9a34d05cf8dfd6723259d3390c74694b Mon Sep 17 00:00:00 2001
From: Alexandru Munteanu <alexandru.munteanu@thinslices.com>
Date: Thu, 25 Jan 2018 14:06:58 +0200
Subject: [PATCH] Fix author adder component

---
 .../src/components/AuthorList/Author.js       | 20 +++++++++----------
 .../src/components/AuthorList/AuthorAdder.js  |  6 +++---
 .../src/components/AuthorList/AuthorList.js   |  1 +
 3 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/packages/components-faraday/src/components/AuthorList/Author.js b/packages/components-faraday/src/components/AuthorList/Author.js
index 50431f538..1c1901529 100644
--- a/packages/components-faraday/src/components/AuthorList/Author.js
+++ b/packages/components-faraday/src/components/AuthorList/Author.js
@@ -52,13 +52,13 @@ export default ({
       </div>
     </div>
     <div className={classnames(classes['button-container'])}>
-      {!isSubmitting && (
+      {editedAuthor < 0 && (
         <div
-          className={classnames(classes['delete-button'])}
-          onClick={removeAuthor(email)}
-          title="Delete author"
+          className={classnames(classes.corresponding)}
+          onClick={setAuthorEdit(index)}
+          title="Edit author"
         >
-          <Icon>trash</Icon>
+          <Icon>edit-2</Icon>
         </div>
       )}
       {!isCorresponding && (
@@ -70,13 +70,13 @@ export default ({
           <Icon>mail</Icon>
         </div>
       )}
-      {editedAuthor < 0 && (
+      {!isSubmitting && (
         <div
-          className={classnames(classes.corresponding)}
-          onClick={setAuthorEdit(index)}
-          title="Edit author"
+          className={classnames(classes['delete-button'])}
+          onClick={removeAuthor(email)}
+          title="Delete author"
         >
-          <Icon>edit-2</Icon>
+          <Icon>trash</Icon>
         </div>
       )}
     </div>
diff --git a/packages/components-faraday/src/components/AuthorList/AuthorAdder.js b/packages/components-faraday/src/components/AuthorList/AuthorAdder.js
index 9c0b574da..5e9587c40 100644
--- a/packages/components-faraday/src/components/AuthorList/AuthorAdder.js
+++ b/packages/components-faraday/src/components/AuthorList/AuthorAdder.js
@@ -67,9 +67,8 @@ export default compose(
   connect(state => ({
     currentUser: selectCurrentUser(state),
   })),
-  withProps(({ currentUser }) => {
-    const { admin, email, username } = currentUser
-    if (!admin) {
+  withProps(({ currentUser: { admin, username, email }, authors }) => {
+    if (!admin && authors.length === 0) {
       return {
         initialValues: {
           email,
@@ -80,6 +79,7 @@ export default compose(
   }),
   reduxForm({
     form: 'author',
+    enableReinitialize: true,
     onSubmit: (
       values,
       dispatch,
diff --git a/packages/components-faraday/src/components/AuthorList/AuthorList.js b/packages/components-faraday/src/components/AuthorList/AuthorList.js
index 7a959a6f9..a3f1c3f1c 100644
--- a/packages/components-faraday/src/components/AuthorList/AuthorList.js
+++ b/packages/components-faraday/src/components/AuthorList/AuthorList.js
@@ -65,6 +65,7 @@ const Authors = ({
       <SortableList
         dragHandle={DragHandle}
         dropItem={dropItem}
+        editedAuthor={editedAuthor}
         items={authors}
         listItem={Author}
         moveItem={moveAuthor}
-- 
GitLab