fix: duct-tape fix the bot edit issues

fixes #629
This commit is contained in:
Paul Makles 2022-06-21 11:14:51 +01:00
parent 3b7c1cbe20
commit 95ebd935ed
3 changed files with 4 additions and 26 deletions

View file

@ -1,5 +1,5 @@
{ {
"version": "1.0.0", "version": "1.0.1",
"scripts": { "scripts": {
"dev": "node scripts/setup_assets.js --check && vite", "dev": "node scripts/setup_assets.js --check && vite",
"pull": "node scripts/setup_assets.js", "pull": "node scripts/setup_assets.js",

View file

@ -29,6 +29,7 @@ export function CreateBotModal({ onClose, onCreate }: Props) {
try { try {
const { bot } = await client.bots.create({ name }); const { bot } = await client.bots.create({ name });
onCreate(bot); onCreate(bot);
onClose();
} catch (err) { } catch (err) {
setError(takeError(err)); setError(takeError(err));
} }

View file

@ -99,12 +99,6 @@ function BotCard({ bot, onDelete, onUpdate }: Props) {
client.api client.api
.get(`/users/${bot._id as ""}/profile`, undefined, { .get(`/users/${bot._id as ""}/profile`, undefined, {
headers: { "x-bot-token": bot.token }, headers: { "x-bot-token": bot.token },
transformRequest: (data, headers) => {
// Remove user headers for this request
delete headers?.["x-user-id"];
delete headers?.["x-session-token"];
return data;
},
}) })
.then((profile) => setProfile(profile ?? {})); .then((profile) => setProfile(profile ?? {}));
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
@ -130,7 +124,8 @@ function BotCard({ bot, onDelete, onUpdate }: Props) {
setSaving(true); setSaving(true);
setError(""); setError("");
try { try {
await client.bots.edit(bot._id, changes); if (Object.keys(changes).length > 0)
await client.bots.edit(bot._id, changes);
if (changed) await editBotContent(profile?.content ?? undefined); if (changed) await editBotContent(profile?.content ?? undefined);
onUpdate(changes); onUpdate(changes);
setChanged(false); setChanged(false);
@ -159,12 +154,6 @@ function BotCard({ bot, onDelete, onUpdate }: Props) {
avatar ? { avatar } : { remove: ["Avatar"] }, avatar ? { avatar } : { remove: ["Avatar"] },
{ {
headers: { "x-bot-token": bot.token }, headers: { "x-bot-token": bot.token },
transformRequest: (data, headers) => {
// Remove user headers for this request
delete headers?.["x-user-id"];
delete headers?.["x-session-token"];
return JSON.stringify(data);
},
}, },
); );
@ -184,12 +173,6 @@ function BotCard({ bot, onDelete, onUpdate }: Props) {
: { remove: ["ProfileBackground"] }, : { remove: ["ProfileBackground"] },
{ {
headers: { "x-bot-token": bot.token }, headers: { "x-bot-token": bot.token },
transformRequest: (data, headers) => {
// Remove user headers for this request
delete headers?.["x-user-id"];
delete headers?.["x-session-token"];
return JSON.stringify(data);
},
}, },
); );
@ -206,12 +189,6 @@ function BotCard({ bot, onDelete, onUpdate }: Props) {
content ? { profile: { content } } : { remove: ["ProfileContent"] }, content ? { profile: { content } } : { remove: ["ProfileContent"] },
{ {
headers: { "x-bot-token": bot.token }, headers: { "x-bot-token": bot.token },
transformRequest: (data, headers) => {
// Remove user headers for this request
delete headers?.["x-user-id"];
delete headers?.["x-session-token"];
return data;
},
}, },
); );