Fix success on user delete failure
This commit is contained in:
parent
fae864dbf5
commit
1d8f154247
|
|
@ -38,15 +38,12 @@ export default function UserDeleteModal() {
|
||||||
mutationFn: async ({ id }: { id: string }) => {
|
mutationFn: async ({ id }: { id: string }) => {
|
||||||
return await deleteUser(id);
|
return await deleteUser(id);
|
||||||
},
|
},
|
||||||
onError: (error) => {
|
onError: (error: unknown) => {
|
||||||
try {
|
if (error instanceof Error) {
|
||||||
const message = JSON.parse(error.message);
|
|
||||||
notifications.show({
|
notifications.show({
|
||||||
message: message.message ?? "Failed to delete User.",
|
message: error.message,
|
||||||
color: "red",
|
color: "red",
|
||||||
});
|
});
|
||||||
} catch (e) {
|
|
||||||
console.log(error);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
|
|
|
||||||
|
|
@ -59,8 +59,10 @@ export const updateUser = async (
|
||||||
};
|
};
|
||||||
|
|
||||||
export const deleteUser = async (id: string) => {
|
export const deleteUser = async (id: string) => {
|
||||||
return await client.users[":id"].$delete({
|
return await fetchRPC(
|
||||||
param: { id },
|
client.users[":id"].$delete({
|
||||||
form: {},
|
param: { id },
|
||||||
});
|
form: {},
|
||||||
|
})
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ import { ReactNode } from "@tanstack/react-router";
|
||||||
|
|
||||||
type GeneralInputProps = {
|
type GeneralInputProps = {
|
||||||
hidden?: boolean;
|
hidden?: boolean;
|
||||||
|
key?: string | number;
|
||||||
};
|
};
|
||||||
|
|
||||||
type TextInputType = {
|
type TextInputType = {
|
||||||
|
|
@ -83,12 +84,13 @@ interface Options {
|
||||||
function createInputComponents(options: Options) {
|
function createInputComponents(options: Options) {
|
||||||
const components = [] as ReactNode[];
|
const components = [] as ReactNode[];
|
||||||
|
|
||||||
const createComponent = (input: AcceptedInput) => {
|
const createComponent = ({ key, ...input }: AcceptedInput) => {
|
||||||
switch (input.type) {
|
switch (input.type) {
|
||||||
case "text":
|
case "text":
|
||||||
return (
|
return (
|
||||||
<TextInput
|
<TextInput
|
||||||
{...input}
|
{...input}
|
||||||
|
key={key}
|
||||||
readOnly={options.readonlyAll || input.readOnly}
|
readOnly={options.readonlyAll || input.readOnly}
|
||||||
disabled={options.disableAll || input.disabled}
|
disabled={options.disableAll || input.disabled}
|
||||||
/>
|
/>
|
||||||
|
|
@ -97,6 +99,7 @@ function createInputComponents(options: Options) {
|
||||||
return (
|
return (
|
||||||
<MultiSelect
|
<MultiSelect
|
||||||
{...input}
|
{...input}
|
||||||
|
key={key}
|
||||||
readOnly={options.readonlyAll || input.readOnly}
|
readOnly={options.readonlyAll || input.readOnly}
|
||||||
disabled={options.disableAll || input.disabled}
|
disabled={options.disableAll || input.disabled}
|
||||||
/>
|
/>
|
||||||
|
|
@ -105,6 +108,7 @@ function createInputComponents(options: Options) {
|
||||||
return (
|
return (
|
||||||
<PasswordInput
|
<PasswordInput
|
||||||
{...input}
|
{...input}
|
||||||
|
key={key}
|
||||||
readOnly={options.readonlyAll || input.readOnly}
|
readOnly={options.readonlyAll || input.readOnly}
|
||||||
disabled={options.disableAll || input.disabled}
|
disabled={options.disableAll || input.disabled}
|
||||||
/>
|
/>
|
||||||
|
|
@ -113,6 +117,7 @@ function createInputComponents(options: Options) {
|
||||||
return (
|
return (
|
||||||
<NumberInput
|
<NumberInput
|
||||||
{...input}
|
{...input}
|
||||||
|
key={key}
|
||||||
type="text"
|
type="text"
|
||||||
readOnly={options.readonlyAll || input.readOnly}
|
readOnly={options.readonlyAll || input.readOnly}
|
||||||
disabled={options.disableAll || input.disabled}
|
disabled={options.disableAll || input.disabled}
|
||||||
|
|
@ -122,6 +127,7 @@ function createInputComponents(options: Options) {
|
||||||
return (
|
return (
|
||||||
<Select
|
<Select
|
||||||
{...input}
|
{...input}
|
||||||
|
key={key}
|
||||||
readOnly={options.readonlyAll || input.readOnly}
|
readOnly={options.readonlyAll || input.readOnly}
|
||||||
disabled={options.disableAll || input.disabled}
|
disabled={options.disableAll || input.disabled}
|
||||||
/>
|
/>
|
||||||
|
|
@ -130,19 +136,24 @@ function createInputComponents(options: Options) {
|
||||||
case "group": {
|
case "group": {
|
||||||
const localComponents: ReactNode[] = [];
|
const localComponents: ReactNode[] = [];
|
||||||
|
|
||||||
for (const child of input.inputs) {
|
for (const [key, child] of input.inputs.entries()) {
|
||||||
if (child.hidden) continue;
|
if (child.hidden) continue;
|
||||||
|
|
||||||
localComponents.push(createComponent(child));
|
localComponents.push(createComponent({ ...child, key }));
|
||||||
}
|
}
|
||||||
|
|
||||||
return <Fieldset {...input}>{localComponents}</Fieldset>;
|
return (
|
||||||
|
<Fieldset key={key} {...input}>
|
||||||
|
{localComponents}
|
||||||
|
</Fieldset>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
case "chip": {
|
case "chip": {
|
||||||
return (
|
return (
|
||||||
<Chip
|
<Chip
|
||||||
{...input}
|
{...input}
|
||||||
|
key={key}
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
readOnly={options.readonlyAll || input.readOnly}
|
readOnly={options.readonlyAll || input.readOnly}
|
||||||
disabled={options.disableAll || input.disabled}
|
disabled={options.disableAll || input.disabled}
|
||||||
|
|
@ -154,6 +165,7 @@ function createInputComponents(options: Options) {
|
||||||
return (
|
return (
|
||||||
<Checkbox
|
<Checkbox
|
||||||
{...input}
|
{...input}
|
||||||
|
key={key}
|
||||||
readOnly={options.readonlyAll || input.readOnly}
|
readOnly={options.readonlyAll || input.readOnly}
|
||||||
disabled={options.disableAll || input.disabled}
|
disabled={options.disableAll || input.disabled}
|
||||||
/>
|
/>
|
||||||
|
|
@ -164,6 +176,7 @@ function createInputComponents(options: Options) {
|
||||||
return (
|
return (
|
||||||
<Textarea
|
<Textarea
|
||||||
{...input}
|
{...input}
|
||||||
|
key={key}
|
||||||
readOnly={options.readonlyAll || input.readOnly}
|
readOnly={options.readonlyAll || input.readOnly}
|
||||||
disabled={options.disableAll || input.disabled}
|
disabled={options.disableAll || input.disabled}
|
||||||
/>
|
/>
|
||||||
|
|
@ -172,10 +185,10 @@ function createInputComponents(options: Options) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const input of options.inputs) {
|
for (const [index, input] of options.inputs.entries()) {
|
||||||
if (input.hidden) continue;
|
if (input.hidden) continue;
|
||||||
|
|
||||||
components.push(createComponent(input));
|
components.push(createComponent({ ...input, key: index }));
|
||||||
}
|
}
|
||||||
|
|
||||||
return <>{components}</>;
|
return <>{components}</>;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user