A few react-admin upgrades
as per https://marmelab.com/react-admin/Upgrade.html
This commit is contained in:
parent
cdccc7f062
commit
49650795df
6 changed files with 41 additions and 34 deletions
|
|
@ -138,7 +138,7 @@ const handleRequestCode = async ({
|
||||||
verifyMode,
|
verifyMode,
|
||||||
id,
|
id,
|
||||||
onSuccess,
|
onSuccess,
|
||||||
onFailure,
|
onError,
|
||||||
captchaCode = undefined,
|
captchaCode = undefined,
|
||||||
}: any) => {
|
}: any) => {
|
||||||
if (verifyMode === MODE.SMS) console.log("REQUESTING sms");
|
if (verifyMode === MODE.SMS) console.log("REQUESTING sms");
|
||||||
|
|
@ -160,7 +160,7 @@ const handleRequestCode = async ({
|
||||||
if (response && response.ok) {
|
if (response && response.ok) {
|
||||||
onSuccess();
|
onSuccess();
|
||||||
} else {
|
} else {
|
||||||
onFailure(response.status || 400);
|
onError(response.status || 400);
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error("Failed to request verification code:", error);
|
console.error("Failed to request verification code:", error);
|
||||||
|
|
@ -171,7 +171,7 @@ const VerificationCodeRequest = ({
|
||||||
verifyMode,
|
verifyMode,
|
||||||
data,
|
data,
|
||||||
onSuccess,
|
onSuccess,
|
||||||
onFailure,
|
onError,
|
||||||
}: any) => {
|
}: any) => {
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
(async () => {
|
(async () => {
|
||||||
|
|
@ -179,10 +179,10 @@ const VerificationCodeRequest = ({
|
||||||
verifyMode,
|
verifyMode,
|
||||||
id: data.id,
|
id: data.id,
|
||||||
onSuccess,
|
onSuccess,
|
||||||
onFailure,
|
onError,
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
}, [data.id, onFailure, onSuccess, verifyMode]);
|
}, [data.id, onError, onSuccess, verifyMode]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|
@ -204,7 +204,7 @@ const VerificationCaptcha = ({
|
||||||
verifyMode,
|
verifyMode,
|
||||||
data,
|
data,
|
||||||
onSuccess,
|
onSuccess,
|
||||||
onFailure,
|
onError,
|
||||||
handleClose,
|
handleClose,
|
||||||
}: any) => {
|
}: any) => {
|
||||||
const [code, setCode] = React.useState(undefined);
|
const [code, setCode] = React.useState(undefined);
|
||||||
|
|
@ -216,7 +216,7 @@ const VerificationCaptcha = ({
|
||||||
verifyMode,
|
verifyMode,
|
||||||
id: data.id,
|
id: data.id,
|
||||||
onSuccess,
|
onSuccess,
|
||||||
onFailure,
|
onError,
|
||||||
captchaCode: code,
|
captchaCode: code,
|
||||||
});
|
});
|
||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
|
|
@ -367,7 +367,7 @@ const VerificationCodeDialog = (props: any) => {
|
||||||
props.handleClose();
|
props.handleClose();
|
||||||
};
|
};
|
||||||
|
|
||||||
const onFailure = (code: number) => {
|
const onError = (code: number) => {
|
||||||
if (code === 402 || code === 500) {
|
if (code === 402 || code === 500) {
|
||||||
setStage("captcha");
|
setStage("captcha");
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -385,7 +385,7 @@ const VerificationCodeDialog = (props: any) => {
|
||||||
<VerificationCodeRequest
|
<VerificationCodeRequest
|
||||||
mode={props.verifyMode}
|
mode={props.verifyMode}
|
||||||
onSuccess={onRequestSuccess}
|
onSuccess={onRequestSuccess}
|
||||||
onFailure={onFailure}
|
onError={onError}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
@ -400,7 +400,7 @@ const VerificationCodeDialog = (props: any) => {
|
||||||
<VerificationCaptcha
|
<VerificationCaptcha
|
||||||
mode={props.verifyMode}
|
mode={props.verifyMode}
|
||||||
onSuccess={onRequestSuccess}
|
onSuccess={onRequestSuccess}
|
||||||
onFailure={onRestartVerification}
|
onError={onRestartVerification}
|
||||||
handleClose={handleClose}
|
handleClose={handleClose}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,10 @@ import {
|
||||||
import { useSession } from "next-auth/react";
|
import { useSession } from "next-auth/react";
|
||||||
import { UserRoleInput } from "./shared";
|
import { UserRoleInput } from "./shared";
|
||||||
|
|
||||||
const UserCreate: FC<CreateProps> = (props: any) => {
|
const UserCreate: FC<CreateProps> = () => {
|
||||||
const { data: session } = useSession();
|
const { data: session } = useSession();
|
||||||
return (
|
return (
|
||||||
<Create {...props} title="Create Users">
|
<Create title="Create Users">
|
||||||
<SimpleForm>
|
<SimpleForm>
|
||||||
<TextInput source="email" />
|
<TextInput source="email" />
|
||||||
<TextInput source="name" />
|
<TextInput source="name" />
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ import {
|
||||||
Toolbar,
|
Toolbar,
|
||||||
SaveButton,
|
SaveButton,
|
||||||
DeleteButton,
|
DeleteButton,
|
||||||
EditProps,
|
|
||||||
useRedirect,
|
useRedirect,
|
||||||
|
useRecordContext,
|
||||||
} from "react-admin";
|
} from "react-admin";
|
||||||
import { useSession } from "next-auth/react";
|
import { useSession } from "next-auth/react";
|
||||||
import { UserRoleInput } from "./shared";
|
import { UserRoleInput } from "./shared";
|
||||||
|
|
@ -23,16 +23,20 @@ const useStyles = makeStyles((_theme: any) => ({
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const UserEditToolbar = (props: any) => {
|
const UserEditToolbar = (props: any) => {
|
||||||
const classes = useStyles(props);
|
const classes = useStyles();
|
||||||
const redirect = useRedirect();
|
const redirect = useRedirect();
|
||||||
|
const record = useRecordContext();
|
||||||
|
const {session} = props;
|
||||||
|
|
||||||
|
const shouldDisableDelete = !session || !session.user || session.user.id === record.id;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Toolbar className={classes.defaultToolbar} {...props}>
|
<Toolbar className={classes.defaultToolbar}>
|
||||||
<SaveButton
|
<SaveButton
|
||||||
label="save"
|
label="save"
|
||||||
mutationOptions={{ onSuccess: () => redirect("/users") }}
|
mutationOptions={{ onSuccess: () => redirect("/users") }}
|
||||||
/>
|
/>
|
||||||
<DeleteButton disabled={props.session.user.id === props.record.id} />
|
<DeleteButton disabled={shouldDisableDelete} />
|
||||||
</Toolbar>
|
</Toolbar>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
@ -43,11 +47,11 @@ const UserTitle = ({ record }: { record?: any }) => {
|
||||||
return <span>User {title}</span>;
|
return <span>User {title}</span>;
|
||||||
};
|
};
|
||||||
|
|
||||||
const UserEdit = (props: EditProps) => {
|
const UserEdit = () => {
|
||||||
const { data: session } = useSession();
|
const { data: session } = useSession();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Edit title={<UserTitle />} {...props}>
|
<Edit title={<UserTitle />}>
|
||||||
<SimpleForm toolbar={<UserEditToolbar session={session} />}>
|
<SimpleForm toolbar={<UserEditToolbar session={session} />}>
|
||||||
<TextInput disabled source="id" />
|
<TextInput disabled source="id" />
|
||||||
<TextInput source="email" />
|
<TextInput source="email" />
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,8 @@ import {
|
||||||
ListProps,
|
ListProps,
|
||||||
} from "react-admin";
|
} from "react-admin";
|
||||||
|
|
||||||
const UserList = (props: ListProps) => (
|
const UserList = () => (
|
||||||
<List {...props} exporter={false}>
|
<List exporter={false}>
|
||||||
<Datagrid rowClick="edit">
|
<Datagrid rowClick="edit">
|
||||||
<EmailField source="email" />
|
<EmailField source="email" />
|
||||||
<DateField source="emailVerified" />
|
<DateField source="emailVerified" />
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
import { SelectInput } from "react-admin";
|
import { SelectInput, useRecordContext } from "react-admin";
|
||||||
|
|
||||||
export const UserRoleInput = (props: any) => (
|
export const UserRoleInput = (props: any) => {
|
||||||
|
const record = useRecordContext();
|
||||||
|
return (
|
||||||
<SelectInput
|
<SelectInput
|
||||||
source="userRole"
|
source="userRole"
|
||||||
choices={[
|
choices={[
|
||||||
|
|
@ -8,7 +10,8 @@ export const UserRoleInput = (props: any) => (
|
||||||
{ id: "USER", name: "User" },
|
{ id: "USER", name: "User" },
|
||||||
{ id: "ADMIN", name: "Admin" },
|
{ id: "ADMIN", name: "Admin" },
|
||||||
]}
|
]}
|
||||||
disabled={props.session.user.id === props.record.id}
|
disabled={props.session.user.id === record.id}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,7 @@ const Sidebar = ({ record }: any) => {
|
||||||
|
|
||||||
const WhatsappBotShow = (props: ShowProps) => {
|
const WhatsappBotShow = (props: ShowProps) => {
|
||||||
const refresh = useRefresh();
|
const refresh = useRefresh();
|
||||||
const { data } = useGetOne("whatsappBots", props.id as any);
|
const { data } = useGetOne("whatsappBots", {id: props.id});
|
||||||
|
|
||||||
const { data: registerData, error: registerError } = useSWR(
|
const { data: registerData, error: registerError } = useSWR(
|
||||||
data && !data?.isVerified
|
data && !data?.isVerified
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue