-
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
326 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import axios from 'axios'; | ||
import BrutalismButton from '../BrutalismButton'; | ||
import { FormattedMessage } from 'react-intl'; | ||
import getCollaborationNotifications from '../../models/notifications/getCollaborationNotifications'; | ||
|
||
export default function CollaborationMessages({ | ||
collaborationTitle, | ||
collaborationData, | ||
setModalOpen, }) { | ||
|
||
// console.log('CollaborationMessages collaborationTitleData:', collaborationTitleData); | ||
|
||
const [loading, setLoading] = useState(false); | ||
const [showError, setShowError] = useState(false); | ||
const [error, setError] = useState(''); | ||
|
||
const content = collaborationData?.map(data => { | ||
const username = data.getAttribute('data-username'); | ||
const access = data.textContent.includes('view-only') ? 'View-Only' : 'Edit'; | ||
const email = data.textContent.match(/\S+@\S+\.\S+/); | ||
const buttons = [...data.querySelectorAll('input[type="button"]')].map(button => { | ||
console.log('button class', button.getAttribute('class')); | ||
console.log('button value', button.getAttribute('value')); | ||
return { | ||
'class': button.getAttribute('class'), | ||
'value': button.getAttribute('value') | ||
} | ||
}); | ||
const id = data.getAttribute('id'); | ||
const collabString = id ? `&collabId=${id.replace("edit-", "")} :` : ''; | ||
|
||
console.log(username, " ------", access, '========', id, '--------', collabString); | ||
|
||
return ( | ||
<div style={{ | ||
display: 'flex', | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
justifyContent: 'space-between', | ||
}}> | ||
|
||
<h6>{username}{' '}({access}) {email}</h6> | ||
<div style={{ | ||
display: 'flex', | ||
flexDirection: 'row', | ||
}}> | ||
{buttons.map(button => ( | ||
<BrutalismButton | ||
style={{ | ||
margin: '0 5px 10px 0', | ||
}} | ||
onClick={async () => { | ||
setLoading(true); | ||
console.log(button.class); | ||
const response = await fetch(`/Collaborate?json=1&username=${username}&approve=${button.class}&actionForExisting=${button.class}${collabString}`); | ||
const data = await response.json(); | ||
setLoading(false); | ||
console.log(data); | ||
if (data.error) { | ||
setShowError(true); | ||
setError(data.error); | ||
} else { | ||
setShowError(false); | ||
getCollaborationNotifications(); | ||
setModalOpen(false); | ||
} | ||
|
||
}} | ||
> | ||
{button.value} | ||
</BrutalismButton> | ||
))} | ||
</div> | ||
</div> | ||
); | ||
}) | ||
|
||
return <> | ||
{collaborationTitle ? <h5>{collaborationTitle}</h5> : <h5><FormattedMessage id="NO_NEW_MESSAGE" /></h5>} | ||
{content} | ||
{showError && <h6>{error}</h6>} | ||
</> | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
import React, { useState } from 'react'; | ||
import BrutalismButton from '../BrutalismButton'; | ||
import { FormattedMessage } from 'react-intl'; | ||
import changeIndividualMergeState from '../../models/notifications/changeIndividualMergeState'; | ||
import getMergeNotifications from '../../models/notifications/getMergeNotifications'; | ||
|
||
export default function MergeMessages({ | ||
mergeData, | ||
setModalOpen, }) { | ||
|
||
console.log('CollaborationMessages mergeData:', mergeData); | ||
|
||
const handleClick = (action, taskId) => { | ||
const result = changeIndividualMergeState(action, taskId); | ||
// setError('Error: ' + result); | ||
getMergeNotifications(); | ||
setModalOpen(false); | ||
} | ||
|
||
const [showError, setShowError] = useState(false); | ||
const [error, setError] = useState(''); | ||
|
||
const content = mergeData?.map(data => { | ||
|
||
const mergePending = data.notificationType === 'mergePending'; | ||
const mergeComplete = data.notificationType === 'mergeComplete'; | ||
const mergeDenied = data.notificationType === 'mergeDenied'; | ||
const ownedByMe = data.ownedByMe === 'true'; | ||
|
||
console.log('each data:', data.ownedByMe); | ||
return <div style={{ | ||
borderBottom: '1px solid #ccc', | ||
padding: '10px', | ||
}}> | ||
|
||
{ | ||
mergePending && <p> | ||
<FormattedMessage id="MERGE_PENDING_MESSAGE" values={{ | ||
indv1: data.primaryIndividualName, | ||
indv2: data.secondaryIndividualName, | ||
initiator: data.initiator, | ||
mergeDate: data.mergeExecutionDate, | ||
bold: chunks => <strong>{chunks}</strong>, | ||
}} /> | ||
</p> | ||
} | ||
|
||
{ | ||
mergeComplete && <p> | ||
<FormattedMessage id="MERGE_COMPLETE_MESSAGE" values={{ | ||
indv1: data.primaryIndividualName, | ||
indv2: data.secondaryIndividualName, | ||
initiator: data.initiator, | ||
mergeDate: data.mergeExecutionDate, | ||
bold: chunks => <strong>{chunks}</strong>, | ||
}} /> | ||
</p> | ||
} | ||
|
||
{ | ||
mergeDenied && <p> | ||
<FormattedMessage id="MERGE_DENIED_MESSAGE" values={{ | ||
indv1: data.primaryIndividualName, | ||
indv2: data.secondaryIndividualName, | ||
initiator: data.initiator, | ||
deniedBy: data.deniedBy, | ||
mergeDate: data.mergeExecutionDate, | ||
bold: chunks => <strong>{chunks}</strong>, | ||
}} /> | ||
</p> | ||
} | ||
|
||
{ | ||
!ownedByMe && mergePending && | ||
<div style={{ | ||
display: 'flex', | ||
flexDirection: 'row', | ||
marginTop: '10px', | ||
marginBottom: '10px', | ||
}}> | ||
<BrutalismButton onClick={() => handleClick('ignore', data.taskId)} > | ||
<FormattedMessage id="IGNORE" /> | ||
</BrutalismButton> | ||
<BrutalismButton onClick={() => handleClick('deny', data.taskId)}> | ||
<FormattedMessage id="DENY" /> | ||
</BrutalismButton> | ||
</div> | ||
} | ||
|
||
{ | ||
mergeComplete && | ||
<div style={{ | ||
display: 'flex', | ||
marginTop: '10px', | ||
marginBottom: '10px', | ||
// width: 105 | ||
}}> | ||
<BrutalismButton onClick={() => handleClick('ignore', data.taskId)} > | ||
<FormattedMessage id="DISMISS" /> | ||
</BrutalismButton> | ||
</div> | ||
} | ||
|
||
{ | ||
mergeDenied && | ||
<div style={{ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
marginTop: '10px', | ||
marginBottom: '10px', | ||
width: '112px' | ||
}}> | ||
<BrutalismButton onClick={() => handleClick('ignore', data.taskId)}> | ||
<FormattedMessage id="DISMISS" /> | ||
</BrutalismButton> | ||
</div> | ||
} | ||
|
||
{ | ||
ownedByMe | ||
? <p> | ||
<FormattedMessage | ||
id="INITIATED_BY_USER" | ||
values={{ | ||
user: 'current user', | ||
bold: chunks => <strong>{chunks}</strong>, | ||
}} | ||
|
||
/> | ||
</p> | ||
: <p> | ||
<FormattedMessage | ||
id="INITIATED_BY_USER" | ||
values={{ | ||
user: data.initiator, | ||
bold: chunks => <strong>{chunks}</strong>, | ||
}} /> | ||
</p> | ||
} | ||
|
||
</div> | ||
}) | ||
|
||
return <div style={{ | ||
maxHeight: '500px', | ||
overflow: 'auto', | ||
}}> | ||
<h4><FormattedMessage id="INDIVIDUAL_MERGE_NOTIFICATIONS" /></h4> | ||
{content} | ||
{showError && <h6>{error}</h6>} | ||
</div> | ||
} | ||
|
||
|
Oops, something went wrong.