UI rework + premium check
This commit is contained in:
parent
677f405826
commit
34c555dbd4
@ -3,8 +3,11 @@ package customisation
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/TicketsBot/GoPanel/botcontext"
|
||||||
dbclient "github.com/TicketsBot/GoPanel/database"
|
dbclient "github.com/TicketsBot/GoPanel/database"
|
||||||
|
"github.com/TicketsBot/GoPanel/rpc"
|
||||||
"github.com/TicketsBot/GoPanel/utils"
|
"github.com/TicketsBot/GoPanel/utils"
|
||||||
|
"github.com/TicketsBot/common/premium"
|
||||||
"github.com/TicketsBot/worker/bot/customisation"
|
"github.com/TicketsBot/worker/bot/customisation"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
@ -14,6 +17,24 @@ import (
|
|||||||
func UpdateColours(ctx *gin.Context) {
|
func UpdateColours(ctx *gin.Context) {
|
||||||
guildId := ctx.Keys["guildid"].(uint64)
|
guildId := ctx.Keys["guildid"].(uint64)
|
||||||
|
|
||||||
|
botContext, err := botcontext.ContextForGuild(guildId)
|
||||||
|
if err != nil {
|
||||||
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Allow votes
|
||||||
|
premiumTier, err := rpc.PremiumClient.GetTierByGuildId(guildId, true, botContext.Token, botContext.RateLimiter)
|
||||||
|
if err != nil {
|
||||||
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if premiumTier < premium.Premium {
|
||||||
|
ctx.JSON(402, utils.ErrorStr("You must have premium to customise message appearance"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var data map[customisation.Colour]utils.HexColour
|
var data map[customisation.Colour]utils.HexColour
|
||||||
if err := ctx.BindJSON(&data); err != nil {
|
if err := ctx.BindJSON(&data); err != nil {
|
||||||
ctx.JSON(400, utils.ErrorJson(err))
|
ctx.JSON(400, utils.ErrorJson(err))
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"github.com/TicketsBot/GoPanel/utils"
|
"github.com/TicketsBot/GoPanel/utils"
|
||||||
"github.com/TicketsBot/common/premium"
|
"github.com/TicketsBot/common/premium"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
func PremiumHandler(ctx *gin.Context) {
|
func PremiumHandler(ctx *gin.Context) {
|
||||||
@ -20,7 +21,10 @@ func PremiumHandler(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
premiumTier, err := rpc.PremiumClient.GetTierByGuildId(guildId, true, botContext.Token, botContext.RateLimiter)
|
// If error, will default to false
|
||||||
|
includeVoting, _ := strconv.ParseBool(ctx.Query("include_voting"))
|
||||||
|
|
||||||
|
premiumTier, err := rpc.PremiumClient.GetTierByGuildId(guildId, includeVoting, botContext.Token, botContext.RateLimiter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, utils.ErrorJson(err))
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
return
|
return
|
||||||
|
@ -35,6 +35,12 @@
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
:global(.link-blue) {
|
||||||
|
color: #3472f7;
|
||||||
|
text-decoration: none;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
.icon {
|
.icon {
|
||||||
width: 24px;
|
width: 24px;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<div class:col-1={col1} class:col-2={col2} class:col-3={col3} class:col-4={col4}>
|
<div class:col-1={col1} class:col-2={col2} class:col-3={col3} class:col-4={col4}>
|
||||||
<label for="input" class="form-label">{label}</label>
|
<label for="input" class="form-label">{label}</label>
|
||||||
<input id="input" class="form-input" type="color" on:input on:change bind:value={value}>
|
<input id="input" class="form-input" type="color" on:input on:change bind:value={value} {disabled}>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
@ -12,6 +12,7 @@
|
|||||||
<script>
|
<script>
|
||||||
export let value;
|
export let value;
|
||||||
export let label;
|
export let label;
|
||||||
|
export let disabled = false;
|
||||||
|
|
||||||
export let col1 = false;
|
export let col1 = false;
|
||||||
export let col2 = false;
|
export let col2 = false;
|
||||||
|
@ -1,29 +1,36 @@
|
|||||||
<div class="parent">
|
<div class="parent">
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<Card footer={false}>
|
<div class="container">
|
||||||
<span slot="title">Looking for whitelabel?</span>
|
<Card footer={false}>
|
||||||
<div slot="body" class="body-wrapper">
|
<span slot="title">Looking for whitelabel?</span>
|
||||||
<p>If you're looking for whitelabel settings (customising bot name and avatar), this is managed on a separate
|
<div slot="body" class="body-wrapper">
|
||||||
page, <Navigate to="/whitelabel" styles="link row">available here</Navigate>.
|
<p>If you're looking for whitelabel settings (customising bot name and avatar), this is managed on a separate
|
||||||
</p>
|
page, <Navigate to="/whitelabel" styles="link-blue">available here</Navigate>.
|
||||||
</div>
|
</p>
|
||||||
</Card>
|
</div>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
|
||||||
<Card footer={false}>
|
<div class="container">
|
||||||
<span slot="title">Colour Scheme</span>
|
<Card footer={false}>
|
||||||
<div slot="body" class="body-wrapper">
|
<div slot="title" class="row">
|
||||||
<form class="settings-form" on:submit|preventDefault={updateColours}>
|
Colour Scheme
|
||||||
<div class="row">
|
<Badge>Premium</Badge>
|
||||||
<Colour col3={true} label="Success" bind:value={colours["0"]} />
|
</div>
|
||||||
<Colour col3={true} label="Failure" bind:value={colours["1"]} />
|
<div slot="body" class="body-wrapper">
|
||||||
</div>
|
<form class="settings-form" on:submit|preventDefault={updateColours}>
|
||||||
|
<div class="row colour-picker-row">
|
||||||
|
<Colour col3={true} label="Success" bind:value={colours["0"]} disabled={!isPremium} />
|
||||||
|
<Colour col3={true} label="Failure" bind:value={colours["1"]} disabled={!isPremium} />
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row centre">
|
||||||
<Button icon="fas fa-paper-plane">Submit</Button>
|
<Button icon="fas fa-paper-plane">Submit</Button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -36,11 +43,13 @@
|
|||||||
import {Navigate} from "svelte-router-spa";
|
import {Navigate} from "svelte-router-spa";
|
||||||
import Colour from "../components/form/Colour.svelte";
|
import Colour from "../components/form/Colour.svelte";
|
||||||
import Button from "../components/Button.svelte";
|
import Button from "../components/Button.svelte";
|
||||||
|
import Badge from "../components/Badge.svelte";
|
||||||
|
|
||||||
export let currentRoute;
|
export let currentRoute;
|
||||||
let guildId = currentRoute.namedParams.id;
|
let guildId = currentRoute.namedParams.id;
|
||||||
|
|
||||||
let colours = {};
|
let colours = {};
|
||||||
|
let isPremium = false;
|
||||||
|
|
||||||
async function updateColours() {
|
async function updateColours() {
|
||||||
const res = await axios.post(`${API_URL}/api/${guildId}/customisation/colours`, colours);
|
const res = await axios.post(`${API_URL}/api/${guildId}/customisation/colours`, colours);
|
||||||
@ -62,8 +71,19 @@
|
|||||||
colours = res.data;
|
colours = res.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function loadPremium() {
|
||||||
|
const res = await axios.get(`${API_URL}/api/${guildId}/premium?include_voting=true`);
|
||||||
|
if (res.status !== 200) {
|
||||||
|
notifyError(res.data.error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
isPremium = res.data.premium;
|
||||||
|
}
|
||||||
|
|
||||||
withLoadingScreen(async () => {
|
withLoadingScreen(async () => {
|
||||||
setDefaultHeaders();
|
setDefaultHeaders();
|
||||||
|
await loadPremium();
|
||||||
await loadColours();
|
await loadColours();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
@ -108,6 +128,20 @@
|
|||||||
margin-bottom: 2%;
|
margin-bottom: 2%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.container {
|
||||||
|
margin-top: 4%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.colour-picker-row {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: space-around;
|
||||||
|
}
|
||||||
|
|
||||||
|
.centre {
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
@media only screen and (max-width: 950px) {
|
@media only screen and (max-width: 950px) {
|
||||||
.row {
|
.row {
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
@ -260,7 +260,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function loadPremium() {
|
async function loadPremium() {
|
||||||
const res = await axios.get(`${API_URL}/api/${guildId}/premium`);
|
const res = await axios.get(`${API_URL}/api/${guildId}/premium?include_voting=false`);
|
||||||
if (res.status !== 200) {
|
if (res.status !== 200) {
|
||||||
notifyError(res.data.error);
|
notifyError(res.data.error);
|
||||||
return;
|
return;
|
||||||
|
@ -115,7 +115,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function loadPremium() {
|
async function loadPremium() {
|
||||||
const res = await axios.get(`${API_URL}/api/${guildId}/premium`);
|
const res = await axios.get(`${API_URL}/api/${guildId}/premium?include_voting=true`);
|
||||||
if (res.status !== 200) {
|
if (res.status !== 200) {
|
||||||
notifyError(res.data.error);
|
notifyError(res.data.error);
|
||||||
return;
|
return;
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
{/if}
|
{/if}
|
||||||
<td>
|
<td>
|
||||||
<Navigate to="/manage/{guildId}/tickets/view/{ticket.id}" styles="link">
|
<Navigate to="/manage/{guildId}/tickets/view/{ticket.id}" styles="link">
|
||||||
<Button type="button"}>View</Button>
|
<Button type="button">View</Button>
|
||||||
</Navigate>
|
</Navigate>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
1
go.sum
1
go.sum
@ -13,7 +13,6 @@ github.com/TicketsBot/common v0.0.0-20210910205523-7ce93fba6fa5 h1:IfNrgUB35hs+M
|
|||||||
github.com/TicketsBot/common v0.0.0-20210910205523-7ce93fba6fa5/go.mod h1:SVwX6gKkxRCMbp+qwJIgvQiy/Ut0fUddexEqRB/NTzc=
|
github.com/TicketsBot/common v0.0.0-20210910205523-7ce93fba6fa5/go.mod h1:SVwX6gKkxRCMbp+qwJIgvQiy/Ut0fUddexEqRB/NTzc=
|
||||||
github.com/TicketsBot/database v0.0.0-20200516170158-fd8a949aec2c/go.mod h1:eky4tBL+IZ0svPgTT0N/9i6j7ygHDQH3784DW+HgfcA=
|
github.com/TicketsBot/database v0.0.0-20200516170158-fd8a949aec2c/go.mod h1:eky4tBL+IZ0svPgTT0N/9i6j7ygHDQH3784DW+HgfcA=
|
||||||
github.com/TicketsBot/database v0.0.0-20210902172951-4e1f8ced84b7/go.mod h1:A4T2uQFIWC/ttCYpfgv7AkPjR09mMRgzG13lgoV/+aI=
|
github.com/TicketsBot/database v0.0.0-20210902172951-4e1f8ced84b7/go.mod h1:A4T2uQFIWC/ttCYpfgv7AkPjR09mMRgzG13lgoV/+aI=
|
||||||
github.com/TicketsBot/database v0.0.0-20211108142700-c406ab0fc1bb h1:hDN153ofF4rmAnA9Rs/j3b/+xazi3QFzQqXSJ6HNgZI=
|
|
||||||
github.com/TicketsBot/database v0.0.0-20211108142700-c406ab0fc1bb/go.mod h1:72oWvH/Gq1iKeXCZhVRZn1JFbNVC5iAgERZWTrEarEo=
|
github.com/TicketsBot/database v0.0.0-20211108142700-c406ab0fc1bb/go.mod h1:72oWvH/Gq1iKeXCZhVRZn1JFbNVC5iAgERZWTrEarEo=
|
||||||
github.com/TicketsBot/database v0.0.0-20211109153802-24100e383d78 h1:zzjOyxCdXN1fGDL2Na6Q82EDU96Cfd1vnlafeY1utUQ=
|
github.com/TicketsBot/database v0.0.0-20211109153802-24100e383d78 h1:zzjOyxCdXN1fGDL2Na6Q82EDU96Cfd1vnlafeY1utUQ=
|
||||||
github.com/TicketsBot/database v0.0.0-20211109153802-24100e383d78/go.mod h1:72oWvH/Gq1iKeXCZhVRZn1JFbNVC5iAgERZWTrEarEo=
|
github.com/TicketsBot/database v0.0.0-20211109153802-24100e383d78/go.mod h1:72oWvH/Gq1iKeXCZhVRZn1JFbNVC5iAgERZWTrEarEo=
|
||||||
|
Loading…
x
Reference in New Issue
Block a user