Panel fixes
This commit is contained in:
parent
8993b31a0b
commit
7336d50d62
@ -174,7 +174,7 @@ func CreatePanel(ctx *gin.Context) {
|
||||
|
||||
ctx.JSON(200, gin.H{
|
||||
"success": true,
|
||||
"panel_id": strconv.Itoa(panelId),
|
||||
"panel_id": panelId,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ func DeletePanel(ctx *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
panelId, err := strconv.Atoi(ctx.Param("id"))
|
||||
panelId, err := strconv.Atoi(ctx.Param("panelid"))
|
||||
if err != nil {
|
||||
ctx.AbortWithStatusJSON(400, gin.H{
|
||||
"success": false,
|
||||
|
@ -33,7 +33,7 @@ func UpdatePanel(ctx *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
panelId, err := strconv.Atoi(ctx.Param("id"))
|
||||
panelId, err := strconv.Atoi(ctx.Param("panelid"))
|
||||
if err != nil {
|
||||
ctx.AbortWithStatusJSON(400, utils.ErrorJson(err))
|
||||
return
|
||||
@ -122,14 +122,8 @@ func UpdatePanel(ctx *gin.Context) {
|
||||
newMessageId := existing.MessageId
|
||||
|
||||
if shouldUpdateMessage {
|
||||
// delete old message
|
||||
if err := rest.DeleteMessage(botContext.Token, botContext.RateLimiter, existing.ChannelId, existing.MessageId); err != nil {
|
||||
ctx.AbortWithStatusJSON(500, gin.H{
|
||||
"success": false,
|
||||
"error": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
// delete old message, ignoring error
|
||||
_ = rest.DeleteMessage(botContext.Token, botContext.RateLimiter, existing.ChannelId, existing.MessageId)
|
||||
|
||||
premiumTier := rpc.PremiumClient.GetTierByGuildId(guildId, true, botContext.Token, botContext.RateLimiter)
|
||||
newMessageId, err = data.sendEmbed(&botContext, existing.Title, existing.CustomId, existing.ReactionEmote, premiumTier > premium.None)
|
||||
@ -147,22 +141,6 @@ func UpdatePanel(ctx *gin.Context) {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Add reaction
|
||||
if err = rest.CreateReaction(botContext.Token, botContext.RateLimiter, data.ChannelId, newMessageId, emoji); err != nil {
|
||||
var unwrapped request.RestError
|
||||
if errors.As(err, &unwrapped) && unwrapped.StatusCode == 403 {
|
||||
ctx.AbortWithStatusJSON(500, gin.H{
|
||||
"success": false,
|
||||
"error": "I do not have permission to add reactions in the specified channel",
|
||||
})
|
||||
} else {
|
||||
// TODO: Most appropriate error?
|
||||
ctx.AbortWithStatusJSON(500, utils.ErrorJson(err))
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Store in DB
|
||||
@ -178,6 +156,7 @@ func UpdatePanel(ctx *gin.Context) {
|
||||
ReactionEmote: emoji,
|
||||
WelcomeMessage: data.WelcomeMessage,
|
||||
WithDefaultTeam: utils.ContainsString(data.Teams, "default"),
|
||||
CustomId: existing.CustomId,
|
||||
}
|
||||
|
||||
if err = dbclient.Client.Panel.Update(panel); err != nil {
|
||||
|
@ -101,8 +101,8 @@ func StartServer() {
|
||||
|
||||
guildAuthApiAdmin.GET("/panels", api_panels.ListPanels)
|
||||
guildAuthApiAdmin.PUT("/panels", api_panels.CreatePanel)
|
||||
guildAuthApiAdmin.PUT("/panels/:id", api_panels.UpdatePanel)
|
||||
guildAuthApiAdmin.DELETE("/panels/:id", api_panels.DeletePanel)
|
||||
guildAuthApiAdmin.PUT("/panels/:panelid", api_panels.UpdatePanel)
|
||||
guildAuthApiAdmin.DELETE("/panels/:panelid", api_panels.DeletePanel)
|
||||
|
||||
guildAuthApiAdmin.GET("/multipanels", api_panels.MultiPanelList)
|
||||
guildAuthApiAdmin.POST("/multipanels", api_panels.MultiPanelCreate)
|
||||
|
@ -98,7 +98,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<input type="hidden" id="edit-message-id">
|
||||
<input type="hidden" id="edit-panel-id">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -114,14 +114,14 @@
|
||||
|
||||
<script>
|
||||
function resetEditModal() {
|
||||
clear('edit-title', 'edit-content', 'edit-message-id', 'edit-reaction', 'edit-welcome-message');
|
||||
clear('edit-title', 'edit-content', 'edit-panel-id', 'edit-reaction', 'edit-welcome-message');
|
||||
$('#edit-mentions').selectpicker('deselectAll');
|
||||
}
|
||||
|
||||
registerHideListener('editmodal');
|
||||
$('#editmodal').on('hidden.bs.modal', resetEditModal);
|
||||
|
||||
async function openEditModal(messageId) {
|
||||
async function openEditModal(panelId) {
|
||||
resetEditModal();
|
||||
|
||||
const res = await axios.get('/api/{{.guildId}}/panels');
|
||||
@ -130,7 +130,7 @@
|
||||
return;
|
||||
}
|
||||
|
||||
const panel = res.data.find(panel => panel.message_id === messageId);
|
||||
const panel = res.data.find(panel => panel.panel_id == panelId);
|
||||
if (panel === undefined) {
|
||||
showToast('Error', 'Panel not found');
|
||||
return;
|
||||
@ -143,7 +143,7 @@
|
||||
}
|
||||
|
||||
async function fillEditData(panel) {
|
||||
document.getElementById('edit-message-id').value = panel.message_id;
|
||||
document.getElementById('edit-panel-id').value = panel.panel_id;
|
||||
document.getElementById('edit-title').value = panel.title;
|
||||
document.getElementById('edit-content').value = panel.content;
|
||||
document.getElementById('edit-colour').value = `#${panel.colour.toString(16)}`;
|
||||
@ -192,19 +192,18 @@
|
||||
values.push(...panel.teams.map((t) => t.id));
|
||||
}
|
||||
|
||||
|
||||
$('#edit-teams').selectpicker('val', values);
|
||||
}
|
||||
|
||||
async function updatePanel() {
|
||||
const messageId = document.getElementById('edit-message-id').value;
|
||||
const panelId = document.getElementById('edit-panel-id').value;
|
||||
const title = document.getElementById('edit-title').value;
|
||||
const content = document.getElementById('edit-content').value;
|
||||
const emote = document.getElementById('edit-reaction').value.replace(':', '');
|
||||
const welcomeMessage = document.getElementById('edit-welcome-message').value;
|
||||
|
||||
const data = {
|
||||
message_id: messageId,
|
||||
panel_id: panelId,
|
||||
title: title === '' ? 'Open a ticket!' : title,
|
||||
content: content === '' ? 'By reacting to this ticket, a message will be opened for you.' : content,
|
||||
emote: emote === '' ? 'envelope_with_arrow' : emote,
|
||||
@ -216,7 +215,7 @@
|
||||
teams: $('#edit-teams').val()
|
||||
};
|
||||
|
||||
const res = await axios.put('/api/{{.guildId}}/panels/' + messageId, data);
|
||||
const res = await axios.put('/api/{{.guildId}}/panels/' + panelId, data);
|
||||
if (res.status === 200 && res.data.success) {
|
||||
showToast('Success', 'Panel updated successfully')
|
||||
$('#editmodal').modal('hide');
|
||||
@ -224,10 +223,9 @@
|
||||
|
||||
// remove old data
|
||||
// TODO: Don't remove just update, looks cleaner
|
||||
const el = document.getElementById(messageId);
|
||||
const el = document.getElementById(panelId);
|
||||
el.parentNode.removeChild(el);
|
||||
|
||||
data.message_id = res.data.message_id;
|
||||
appendPanel(data, await getChannels());
|
||||
} else {
|
||||
showToast('Error', res.data.error);
|
||||
|
Loading…
x
Reference in New Issue
Block a user