Skip to content

Commit f0341ea

Browse files
committed
DEV: Add an option to copy reviewable notes when they're created.
1 parent 52682ad commit f0341ea

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import Component from "@glimmer/component";
2+
import { i18n } from "discourse-i18n";
3+
4+
export default class CopyReviewableNoteToUserOption extends Component {
5+
static shouldRender(args, context) {
6+
return (
7+
context.siteSettings.user_notes_enabled && context.currentUser?.staff
8+
);
9+
}
10+
11+
<template>
12+
<@form.CheckboxGroup as |group|>
13+
<group.Field
14+
@name="copy_note_to_user"
15+
@title={{i18n "user_notes.copy_reviewable_note"}}
16+
@format="full"
17+
as |field|
18+
>
19+
<field.Checkbox />
20+
</group.Field>
21+
</@form.CheckboxGroup>
22+
</template>
23+
}

assets/javascripts/discourse/initializers/enable-user-notes.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { ajax } from "discourse/lib/ajax";
2+
import { popupAjaxError } from "discourse/lib/ajax-error";
13
import { iconNode } from "discourse/lib/icon-library";
24
import { withPluginApi } from "discourse/lib/plugin-api";
35
import { showUserNotes } from "../lib/user-notes";
@@ -109,6 +111,31 @@ export default {
109111
}
110112
},
111113
});
114+
115+
api.onAppEvent(
116+
"reviewablenote:created",
117+
async (data, reviewable, formApi) => {
118+
if (!data.copy_note_to_user || !reviewable.target_created_by) {
119+
return;
120+
}
121+
122+
try {
123+
await ajax("/user_notes", {
124+
type: "POST",
125+
data: {
126+
user_note: {
127+
user_id: reviewable.target_created_by.id,
128+
raw: data.content.trim(),
129+
},
130+
},
131+
});
132+
133+
formApi.set("copy_note_to_user", false);
134+
} catch (error) {
135+
popupAjaxError(error);
136+
}
137+
}
138+
);
112139
});
113140
},
114141
};

config/locales/client.en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ en:
77
show: "User Notes (%{count})"
88
delete_confirm: "Are you sure you want to delete that user note?"
99
show_post: "Show Post"
10+
copy_reviewable_note: "Copy note to user profile?"

0 commit comments

Comments
 (0)