Skip to content

Commit

Permalink
fix: participants can change state of goals
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisVorop committed Feb 20, 2024
1 parent 1695416 commit 6ba1390
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
3 changes: 1 addition & 2 deletions src/components/CommentForm/CommentForm.module.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
.FormHelpButton {
display: flex;
align-items: center;
justify-content: space-between;
padding-top: var(--gap-m);
margin-right: auto;
}

.CommentFormWrapper {
Expand Down
8 changes: 3 additions & 5 deletions src/components/CommentForm/CommentForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,9 @@ export const CommentForm: React.FC<CommentFormProps> = ({

{nullable(focused, () => (
<FormActions>
<FormAction left inline>
<div className={s.FormHelpButton}>
<HelpButton slug="comments" />
</div>
</FormAction>
<div className={s.FormHelpButton}>
<HelpButton slug="comments" />
</div>
<FormAction right inline>
{nullable(!busy, () => (
<Button text={tr('Cancel')} onClick={onCommentCancel} />
Expand Down
2 changes: 1 addition & 1 deletion src/components/GoalActivityFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export const GoalActivityFeed = forwardRef<HTMLDivElement, GoalActivityFeedProps
<GoalCommentCreateForm
goalId={goal.id}
stateId={goal.stateId}
states={goal._isEditable ? goal.project?.flow.states : undefined}
states={goal._isEditable || goal._isParticipant ? goal.project?.flow.states : undefined}
onSubmit={onGoalCommentCreate}
/>
}
Expand Down
14 changes: 8 additions & 6 deletions src/utils/db/createComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,16 @@ export const createComment = async ({
if (!commentAuthor) return null;
if (!actualGoal) return null;

const { _isEditable, _shortId } = addCalculatedGoalsFields(actualGoal, activityId, role);
const { _isEditable, _shortId, _isParticipant } = addCalculatedGoalsFields(actualGoal, activityId, role);

const canEdit = _isEditable || _isParticipant;

const commentCreateOperation = prisma.comment.create({
data: {
description,
activityId: commentAuthor.id,
goalId,
stateId: _isEditable ? stateId : undefined,
stateId: canEdit ? stateId : undefined,
},
include: {
activity: {
Expand All @@ -71,19 +73,19 @@ export const createComment = async ({
where: { id: goalId },
data: {
id: goalId,
stateId: _isEditable ? pushState?.id : actualGoal.stateId,
stateId: canEdit ? pushState?.id : actualGoal.stateId,
goalInCriteria: {
updateMany: {
where: {
id: { in: actualGoal.goalInCriteria.map(({ id }) => id) },
},
data: {
isDone: _isEditable && pushState?.type && pushState?.type === StateType.Completed,
isDone: canEdit && pushState?.type && pushState?.type === StateType.Completed,
},
},
},
history:
_isEditable && stateId && stateId !== actualGoal.stateId
canEdit && stateId && stateId !== actualGoal.stateId
? {
create: {
subject: 'state',
Expand All @@ -110,7 +112,7 @@ export const createComment = async ({

await updateProjectUpdatedAt(updatedGoal.projectId);

if (_isEditable && stateId && stateId !== updatedGoal.stateId) {
if (canEdit && stateId && stateId !== updatedGoal.stateId) {
await recalculateCriteriaScore(updatedGoal.id).recalcLinkedGoalsScores().recalcAverageProjectScore().run();
}

Expand Down

0 comments on commit 6ba1390

Please sign in to comment.