You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on May 26, 2024. It is now read-only.
Issue Summary:
I'm encountering an issue with my custom feature. The problem arises when I try to configure the feature, as it gets stuck on "Loading."
Code Files:
features.tsx in config folder
custom-types.tsx in config folder
FruitStocksFeature.tsx in config > use-features folder
Backend server implementation
Description:
I've created a custom feature called "Fruit Stocks" for my bot. The feature itself works well, including the enable feature button. However, when attempting to configure the feature, it gets stuck on "Loading."
features.tsx
config > features.tsx
import{Icon}from'@chakra-ui/react';import{FaAppleAlt}from'react-icons/fa';import{FeaturesConfig}from'./types';import{provider}from'@/config/translations/provider';import{createI18n}from'@/utils/i18n';import{useFruitStocksFeature}from"./use-features/FruitStocksFeature";/** * Support i18n (Localization) */const{ T }=createI18n(provider,{en: {fruitStocks: "Fruit Stocks",'fruitStocks description': 'Blox Fruit\'s stock notifier',},});/** * Define information for each features * * There is an example: */exportconstfeatures: FeaturesConfig={fruitStocks: {name: <Ttext="fruitStocks"/>,description: <Ttext="fruitStocks description"/>,icon: <Iconas={FaAppleAlt}/>,useRender: useFruitStocksFeature,}};
custom-types.tsx
config > types
/*** * Custom types that should be configured by developer ***/import{z}from'zod';import{GuildInfo}from'./types';exporttypeCustomGuildInfo=GuildInfo&{};/** * Define feature ids and it's option types */exporttypeCustomFeatures={fruitStocks: FruitStocksFeature;};/** * Define feature ids and it's option types */exporttypeFruitStocksFeature={channel?: string;};
FruitStocksFeature.tsx
config > use-features Note: use-feature is a folder that I made to store all of my custom features.
import{SimpleGrid}from'@chakra-ui/layout';import{TextAreaForm}from'@/components/forms/TextAreaForm';import{UseFormRender,FruitStocksFeature}from'@/config/types';import{useForm}from'react-hook-form';import{zodResolver}from'@hookform/resolvers/zod';import{z}from'zod';import{ColorPickerForm,SmallColorPickerForm}from'@/components/forms/ColorPicker';import{DatePickerForm}from'@/components/forms/DatePicker';import{FilePickerForm}from'@/components/forms/FilePicker';import{SwitchFieldForm}from'@/components/forms/SwitchField';import{ChannelSelectForm}from'@/components/forms/ChannelSelect';constschema=z.object({channel: z.string(),danger: z.boolean(),});typeInput=z.infer<typeofschema>;exportconstuseFruitStocksFeature: UseFormRender<FruitStocksFeature>=(data,onSubmit)=>{const{ register, reset, handleSubmit, formState, control }=useForm<Input>({resolver: zodResolver(schema),shouldUnregister: false,defaultValues: {channel: data.channel,danger: false,},});console.log("HELLO FRUIT STOCKS")return{component: (<SimpleGridcolumns={{base: 1,lg: 2}}gap={3}><ChannelSelectFormcontrol={{label: 'Channel',description: 'Where to send the welcome message',}}controller={{control,name: 'channel'}}/><SwitchFieldFormcontrol={{label: 'Turn on',description: 'Enable something'}}controller={{
control,name: 'danger',}}/></SimpleGrid>),onSubmit: handleSubmit(async(e)=>{constdata=awaitonSubmit(JSON.stringify({channel: e.channel,}));reset(data);}),canSave: formState.isDirty,reset: ()=>reset(control._defaultValues),};};
Backend Server Implementation
Note: This code is only the "listening" to a certain route and I have the backend server working. It is using express.js and is running alongside with my actual bot.
module.exports=(client,server,utils)=>{server.get("/guilds/:id/features/fruitStocks",async(req,res)=>{try{console.log("trying to get")constguild=client.guilds.cache.get(req.params.id);constschema=awaitclient.mongoose.schemas.guilds.findOne({guildId: guild.id})if(!schema){returnres.status(404).json({error: "Guild schema not found"});}constfruitStocks=schema.modules.fruitStocks;console.log("Im here")return{channel: "1180089709196738561"}}catch(error){console.error(error);returnres.status(500).json({error: `Internal server error. ${error}`})}})server.post("/guilds/:id/features/fruitStocks",async(req,res)=>{try{console.log("trying to post")awaitutils.checkPermission(req.session,req.params.id);constguild=client.guilds.cache.get(req.params.id);constschema=awaitclient.mongoose.schemas.guilds.findOne({guildId: guild.id})if(!schema){returnres.status(404).json({error: "Guild schema not found"});}schema.modules.fruitStocks.enabled=trueawaitschema.save()return"Success"}catch(error){console.error(error);returnres.status(500).json({error: `Internal server error. ${error}`})}})server.delete("/guilds/:id/features/fruitStocks",async(req,res)=>{try{console.log("trying to delete")awaitutils.checkPermission(req.session,req.params.id);constguild=client.guilds.cache.get(req.params.id);constschema=awaitclient.mongoose.schemas.guilds.findOne({guildId: guild.id})if(!schema){returnres.status(404).json({error: "Guild schema not found"});}schema.modules.fruitStocks.enabled=falseawaitschema.save()return"Success"}catch(error){console.error(error);returnres.status(500).json({error: `Internal server error. ${error}`})}})server.patch("/guilds/:id/features/fruitStocks",async(req,res)=>{try{console.log("trying to patch")awaitutils.checkPermission(req.session,req.params.id);constguild=client.guilds.cache.get(req.params.id);constschema=awaitclient.mongoose.schemas.guilds.findOne({guildId: guild.id})if(!schema){returnres.status(404).json({error: "Guild schema not found"});}}catch(error){console.error(error);returnres.status(500).json({error: `Internal server error. ${error}`})}})}
Any Help Appreciated:
I would appreciate any guidance or assistance in resolving this issue. If more code files or information are needed, please let me know.
Thank you for your help!
The text was updated successfully, but these errors were encountered:
Check your devtools and see if any requests failed
No requests failed (404, etc), but I saw 2 requests for /guilds/:id/features/fruitStock. One with a status of 204, and the other with a status of pending.
Issue Summary:
I'm encountering an issue with my custom feature. The problem arises when I try to configure the feature, as it gets stuck on "Loading."
Code Files:
Description:
I've created a custom feature called "Fruit Stocks" for my bot. The feature itself works well, including the enable feature button. However, when attempting to configure the feature, it gets stuck on "Loading."
features.tsx
config > features.tsx
custom-types.tsx
config > types
FruitStocksFeature.tsx
config > use-features
Note:
use-feature
is a folder that I made to store all of my custom features.Backend Server Implementation
Note: This code is only the "listening" to a certain route and I have the backend server working. It is using
express.js
and is running alongside with my actual bot.Any Help Appreciated:
I would appreciate any guidance or assistance in resolving this issue. If more code files or information are needed, please let me know.
Thank you for your help!
The text was updated successfully, but these errors were encountered: