changed form reset and fixed systemvoice

This commit is contained in:
Polaris
2024-08-26 20:06:33 -04:00
parent bfe2403076
commit e22708f98a
9 changed files with 19 additions and 79 deletions

View File

@ -142,14 +142,11 @@ export const AvatarCustomization: FC<AvatarSelectionProps> = ({
toast({ toast({
title: "Avatar updated successfully!", title: "Avatar updated successfully!",
description: ( description: (
<pre className="mt-2 w-[340px] rounded-md bg-slate-950 p-4"> <pre className="mt-2 w-[340px] rounded-md p-4">
<code className="text-white"> <div className="text-white">Avatar updated</div>
{JSON.stringify(data, null, 2)}
</code>
</pre> </pre>
), ),
}); });
resetFormValues();
}) })
.catch((error) => { .catch((error) => {
toast({ toast({
@ -160,15 +157,6 @@ export const AvatarCustomization: FC<AvatarSelectionProps> = ({
}); });
} }
function resetFormValues() {
form.reset({
AvatarHeadAccessory: undefined,
AvatarFaceAccessory: undefined,
AvatarItemAccessory: undefined,
AvatarBackAccessory: undefined,
AvatarWearAccessory: undefined,
});
}
const getTexture = (id: number | undefined, defaultSrc: string) => { const getTexture = (id: number | undefined, defaultSrc: string) => {
return id ? getAvatarTextureSrc(id) : defaultSrc; return id ? getAvatarTextureSrc(id) : defaultSrc;
}; };

View File

@ -33,7 +33,7 @@ export async function updatePlayerMapIcon(mapIconId?: number) {
} }
if (mapIconId === undefined) { if (mapIconId === undefined) {
throw new Error("nameplateId is required"); throw new Error("map icon is required");
} }
try { try {
@ -51,7 +51,7 @@ export async function updatePlayerMapIcon(mapIconId?: number) {
return updatePlayerMapIconId; return updatePlayerMapIconId;
} catch (error) { } catch (error) {
console.error("Error updating nameplate:", error); console.error("Error updating map icon:", error);
throw error; throw error;
} }
} }

View File

@ -64,7 +64,7 @@ export const MapIconCustomization: FC<SystemVoiceSelectionProps> = ({
try { try {
const data = await getCurrentMapIcon(); const data = await getCurrentMapIcon();
if (data.length > 0) { if (data.length > 0) {
setMapIconId(data[0].mapIconId ?? undefined); // Handle null as undefined setMapIconId(data[0].mapIconId ?? undefined);
form.setValue("mapIconId", data[0].mapIconId as number); form.setValue("mapIconId", data[0].mapIconId as number);
} }
} catch (error) { } catch (error) {
@ -82,22 +82,15 @@ export const MapIconCustomization: FC<SystemVoiceSelectionProps> = ({
updatePlayerMapIcon(newMapIconId).then(() => { updatePlayerMapIcon(newMapIconId).then(() => {
setMapIconId(newMapIconId); setMapIconId(newMapIconId);
}); });
resetFormValues();
toast({ toast({
title: "You submitted the following values:", title: "You submitted the following values:",
description: ( description: (
<pre className="mt-2 w-[340px] rounded-md bg-slate-950 p-4"> <pre className="mt-2 w-[340px] rounded-md p-4">
<code className="text-white">{JSON.stringify(data, null, 2)}</code> <div className="text-white">Map icon updated</div>
</pre> </pre>
), ),
}); });
function resetFormValues() {
form.reset({
mapIconId: undefined,
});
}
} }
const getTexture = (id: number | undefined, defaultSrc: string) => { const getTexture = (id: number | undefined, defaultSrc: string) => {

View File

@ -49,8 +49,6 @@ export async function updatePlayerNamePlate(nameplateId?: number) {
}, },
}); });
console.log(updatePlayerNameplate);
return updatePlayerNameplate; return updatePlayerNameplate;
} catch (error) { } catch (error) {
console.error("Error updating nameplate:", error); console.error("Error updating nameplate:", error);

View File

@ -84,22 +84,15 @@ export const NameplateCustomization: FC<NamePlateSelectionProps> = ({
updatePlayerNamePlate(newNamePlateId).then(() => { updatePlayerNamePlate(newNamePlateId).then(() => {
setNameplateId(newNamePlateId); setNameplateId(newNamePlateId);
}); });
resetFormValues();
toast({ toast({
title: "You submitted the following values:", title: "You submitted the following values:",
description: ( description: (
<pre className="mt-2 w-[340px] rounded-md bg-slate-950 p-4"> <pre className="mt-2 w-[340px] rounded-md p-4">
<code className="text-white">{JSON.stringify(data, null, 2)}</code> <code className="text-white">Nameplate updated</code>
</pre> </pre>
), ),
}); });
function resetFormValues() {
form.reset({
nameplateId: undefined,
});
}
} }
const getTexture = (id: number | undefined, defaultSrc: string) => { const getTexture = (id: number | undefined, defaultSrc: string) => {

View File

@ -36,20 +36,6 @@ export async function updatePlayerSystemVoiceId(voiceId: number) {
throw new Error("nameplateId is required"); throw new Error("nameplateId is required");
} }
const checkIfSystemVoiceIsUnlocked = await artemis.chuni_item_item.findMany({
where: {
itemKind: 10,
user: user.UserId,
},
select: {
itemId: true,
},
});
const unlockedSystemVoices = checkIfSystemVoiceIsUnlocked.map(
(item) => item.itemId,
);
try { try {
const updatePlayerNameplate = await artemis.chuni_profile_data.update({ const updatePlayerNameplate = await artemis.chuni_profile_data.update({
where: { where: {
@ -63,9 +49,7 @@ export async function updatePlayerSystemVoiceId(voiceId: number) {
}, },
}); });
console.log(updatePlayerNameplate); return updatePlayerNameplate;
return unlockedSystemVoices;
} catch (error) { } catch (error) {
console.error("Error updating nameplate:", error); console.error("Error updating nameplate:", error);
throw error; throw error;

View File

@ -87,22 +87,15 @@ export const SystemVoiceCustomization: FC<SystemVoiceSelectionProps> = ({
updatePlayerSystemVoiceId(newSystemVoiceId).then(() => { updatePlayerSystemVoiceId(newSystemVoiceId).then(() => {
setSytemVoiceId(newSystemVoiceId); setSytemVoiceId(newSystemVoiceId);
}); });
resetFormValues();
toast({ toast({
title: "You submitted the following values:", title: "You submitted the following values:",
description: ( description: (
<pre className="mt-2 w-[340px] rounded-md bg-slate-950 p-4"> <pre className="rounded-mdp-4 mt-2 w-[340px]">
<code className="text-white">{JSON.stringify(data, null, 2)}</code> <code className="text-white">System voice updated</code>
</pre> </pre>
), ),
}); });
function resetFormValues() {
form.reset({
PlayerSystemVoice: undefined,
});
}
} }
const getTexture = (id: number | undefined, defaultSrc: string) => { const getTexture = (id: number | undefined, defaultSrc: string) => {
@ -116,7 +109,7 @@ export const SystemVoiceCustomization: FC<SystemVoiceSelectionProps> = ({
form.watch("PlayerSystemVoice"), form.watch("PlayerSystemVoice"),
`systemVoiceThumbnails/CHU_UI_SystemVoice_${systemVoiceId.toString().padStart(8, "0")}.png`, `systemVoiceThumbnails/CHU_UI_SystemVoice_${systemVoiceId.toString().padStart(8, "0")}.png`,
) )
: `systemVoiceThumbnails/CHU_UI_SystemVoice_Default.png`, // Provide a default texture or handle the case when systemVoiceId is undefined : `systemVoiceThumbnails/CHU_UI_SystemVoice_Default.png`,
}, },
}; };

View File

@ -33,11 +33,11 @@ export async function updatePlayerTrophy(trophyId: number) {
} }
if (trophyId === undefined) { if (trophyId === undefined) {
throw new Error("nameplateId is required"); throw new Error("trophy is required");
} }
try { try {
const updatePlayerNameplate = await artemis.chuni_profile_data.update({ const updatePlayerTrophies = await artemis.chuni_profile_data.update({
where: { where: {
user_version: { user_version: {
user: user.UserId, user: user.UserId,
@ -49,11 +49,9 @@ export async function updatePlayerTrophy(trophyId: number) {
}, },
}); });
console.log(updatePlayerNameplate); return updatePlayerTrophies;
return updatePlayerNameplate;
} catch (error) { } catch (error) {
console.error("Error updating nameplate:", error); console.error("Error updating trophy:", error);
throw error; throw error;
} }
} }

View File

@ -78,22 +78,15 @@ export const TrophyCustomization: FC<AvatarSelectionProps> = ({
updatePlayerTrophy(newNamePlateId).then(() => { updatePlayerTrophy(newNamePlateId).then(() => {
setTrophyId(newNamePlateId); setTrophyId(newNamePlateId);
}); });
resetFormValues();
toast({ toast({
title: "You submitted the following values:", title: "You submitted the following values:",
description: ( description: (
<pre className="mt-2 w-[340px] rounded-md bg-slate-950 p-4"> <pre className="mt-2 w-[340px] rounded-md p-4">
<code className="text-white">{JSON.stringify(data, null, 2)}</code> <code className="text-white">Trophy updated</code>
</pre> </pre>
), ),
}); });
function resetFormValues() {
form.reset({
trophies: undefined,
});
}
} }
return ( return (