delete confirm modification
I want to modify the content modal that appears when you try to erase a entry using the deleteButton, being more specific i want to add a disable for 3 seconds to the buttons of the modal
Good to know: You can swizzle this component to customize it with the Refine CLI
resource props.useTable also accept generic type parameters for better type safety.useForm hook to prevent any redirection after form submission:<Refine> component:_app.tsx or :false in your useForm hook:<Refine> component:useForm to control the redirection programmatically:<Refine> component that might override your local settingsqueryResult is deprecated in newer versions of refine.queryResult is deprecated and will be removed in future versions:queryResultdeprecated
This prop is deprecated and will be removed in the future versions. Useinstead.query
query property instead of queryResult. Here's how you can update your code:true by default in refine. This can cause the state to remain true even after refetching, as mentioned in this GitHub issue:useForm, you're creating two separate data fetching mechanisms that aren't coordinated with each other.When trying to change viewing record with , and are not triggered.
useForm rather than using a separate hook. Here's how you should modify your code:queryOptions property of useForm to configure how the data is fetched:DeleteButtonDeleteButtonuseDeleteButtonconfirmTitleconfirmTitleconfirmTitleconfirmOkTextconfirmCancelText@refinedev/antd@refinedev/mui@refinedev/chakra-ui@refinedev/mantine? Which package do you want to swizzle? (Use arrow keys or type to search)
Data Provider
◯ @refinedev/simple-rest
UI Framework
◉ @refinedev/antd? Which component do you want to swizzle?
Buttons
◯ CreateButton
◯ ShowButton
◉ DeleteButton
Pages
◯ ErrorPage
◯ AuthPage
(Move up and down to reveal more choices)src/components/buttons/delete-button/recordItemIduseOneuseOneuseOneuseOneuseOneuseOneAre you sure you want to delete ${record.name || record.title || "this record"}?``
This approach allows you to:
1. Fetch the record data using the recordrecord.redirectredirectredirectupdateMutationOptions@refinedev/react-hook-formapp.tsx${errors.name.message}queryResult?.refetch()keepPreviousDataisLoadingisLoadinguseShowsetShowIdisErrorquery.refetch()npm run refine swizzle<DeleteButton
recordItemId={record.id}
confirmTitle={`ARE YOU SURE YOU WANT TO DELETE ${record?.name}???? BE CAREFUL!!!!`}
/>// Example from Mantine UI
{
id: "actions",
header: "Actions",
accessorKey: "id",
cell: function render({ getValue, row }) {
return (
<DeleteButton size="xs" recordItemId={getValue() as number} />
);
},
}// In your list component
<DeleteButton
recordItemId={row.id}
record={row.original} // Pass the entire row data
/>
// In your swizzled DeleteButton component
const DeleteButton = ({
recordItemId,
record, // Access the record directly
confirmTitle: confirmTitleProp,
// ... other props
}) => {
// Use the record directly without fetching
const confirmTitle = record
? `Are you sure you want to delete ${record.name || record.title || "this record"}?`
: confirmTitleProp || "Are you sure?";
// Rest of your component
}<DeleteButton
recordItemId={row.id}
confirmTitle={`Are you sure you want to delete ${row.original.name}?`}
/>import { BaseRecord } from "@refinedev/core";
// Make the component generic with a type parameter
export const DeleteButton = <TData extends BaseRecord = BaseRecord>({
recordItemId,
record,
confirmTitle,
// other props
}: {
recordItemId: number | string;
record?: TData;
confirmTitle?: string;
// other props
}) => {
// Now you can access properties of the record with proper TypeScript support
const displayName = record?.title || record?.name || "this record";
const confirmTitleWithRecord = record
? `Are you sure you want to delete ${displayName}?`
: confirmTitle || "Are you sure?";
// Rest of your component implementation
};// In your list component
<DeleteButton<MyPostType>
recordItemId={row.id}
record={row.original}
/>const { formProps } = useForm({
redirect: false,
// other options
});const {
formProps,
saveButtonProps,
queryResult,
onFinish
} = useForm();
const handleSubmit = async (values) => {
await onFinish(values);
// Refetch data to reload the form with updated values
queryResult?.refetch();
};const App = () => (
<Refine
options={{
redirect: {
afterEdit: false,
},
}}
// other props
/>
);const { formProps } = useForm({
redirect: false,
updateMutationOptions: {
onSuccess: () => {
// Custom logic after successful update
queryResult?.refetch();
}
}
});import { useForm } from "@refinedev/react-hook-form";
import { Edit, TextField, Button } from "@refinedev/mui";
import { Controller } from "react-hook-form";
const YourEditComponent = () => {
const {
refineCore: { onFinish, formLoading, queryResult },
handleSubmit,
control,
formState: { errors },
} = useForm({
// Prevent redirect after submission
redirect: false,
});
// Custom submit handler that refetches data after submission
const onSubmit = async (data) => {
await onFinish(data);
// Refetch data to reload the form with updated values
queryResult?.refetch();
};
return (
<Edit
// Use custom submit handler
saveButtonProps={{
onClick: handleSubmit(onSubmit)
}}
>
<Box component="form">
<Controller
control={control}
name="title"
rules={{ required: "Title is required" }}
render={({ field }) => (
<TextField
{...field}
error={!!errors?.title}
helperText={errors.title && `${errors.title.message}`}
margin="normal"
fullWidth
label="Title"
/>
)}
/>
{/* Other form fields */}
</Box>
</Edit>
);
};import { Refine } from "@refinedev/core";
function MyApp({ Component, pageProps }) {
return (
<Refine
// Other refine configurations
options={{
redirect: {
afterEdit: false,
},
}}
>
<Component {...pageProps} />
</Refine>
);
}
export default MyApp;const {
refineCore: { onFinish, formLoading, queryResult },
handleSubmit,
control,
} = useForm({
refineCoreProps: {
redirect: false,
},
});<Refine
options={{
redirect: {
afterCreate: false,
afterEdit: false,
afterClone: false,
},
}}
// other props
/>const {
refineCore: { onFinish, queryResult },
handleSubmit,
control,
} = useForm();
// Custom submit handler
const submitHandler = async (values) => {
await onFinish(values);
// Don't call redirect function
queryResult?.refetch();
};
return (
<Edit saveButtonProps={{ onClick: handleSubmit(submitHandler) }}>
{/* Form fields */}
</Edit>
);// For React Hook Form
useForm({
refineCoreProps: {
redirect: false,
},
});const {
refineCore: { onFinish, formLoading, query },
handleSubmit,
control,
} = useForm({
refineCoreProps: {
redirect: false,
},
});
// Custom submit handler
const submitHandler = async (values) => {
await onFinish(values);
// Use query.refetch instead of queryResult.refetch
query?.refetch();
};<Refine
options={{
reactQuery: {
clientConfig: {
defaultOptions: {
queries: {
keepPreviousData: false,
},
},
},
},
}}
/>const {
refineCore: { onFinish, query },
handleSubmit,
control,
} = useForm({
refineCoreProps: {
redirect: false,
},
});
// Get more specific loading states
const { isLoading, isFetching, isRefetching } = query || {};
// Custom submit handler
const submitHandler = async (values) => {
await onFinish(values);
query?.refetch();
};
// Use these states to control your UI loading indicators
console.log({ isLoading, isFetching, isRefetching });<RefreshButton
onClick={() => {
query?.refetch();
}}
/>// Instead of this:
const { data, isLoading } = useOne({
resource: "students",
id,
});
// Use the query object from useForm:
const {
refineCore: { onFinish, query },
handleSubmit,
control,
formState: { errors },
} = useForm({
refineCoreProps: {
redirect: false,
},
});
// Access the data and loading state from the query object
const { data, isLoading } = query || {};useForm({
refineCoreProps: {
redirect: false,
queryOptions: {
enabled: !!id,
},
},
});