@refinedev/core 4.55.0 → 4.56.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/CHANGELOG.md +81 -0
  2. package/dist/components/link/index.d.cts +3 -3
  3. package/dist/components/link/index.d.cts.map +1 -1
  4. package/dist/components/link/index.d.mts +3 -3
  5. package/dist/components/link/index.d.mts.map +3 -3
  6. package/dist/components/link/index.d.ts +3 -3
  7. package/dist/components/link/index.d.ts.map +1 -1
  8. package/dist/components/pages/auth/components/forgotPassword/index.d.cts.map +1 -1
  9. package/dist/components/pages/auth/components/forgotPassword/index.d.ts.map +1 -1
  10. package/dist/components/pages/auth/components/login/index.d.cts.map +1 -1
  11. package/dist/components/pages/auth/components/login/index.d.ts.map +1 -1
  12. package/dist/components/pages/auth/components/register/index.d.cts.map +1 -1
  13. package/dist/components/pages/auth/components/register/index.d.ts.map +1 -1
  14. package/dist/components/pages/auth/components/updatePassword/index.d.cts.map +1 -1
  15. package/dist/components/pages/auth/components/updatePassword/index.d.ts.map +1 -1
  16. package/dist/components/pages/auth/types.d.cts +8 -0
  17. package/dist/components/pages/auth/types.d.cts.map +1 -1
  18. package/dist/components/pages/auth/types.d.mts +8 -0
  19. package/dist/components/pages/auth/types.d.mts.map +8 -0
  20. package/dist/components/pages/auth/types.d.ts +8 -0
  21. package/dist/components/pages/auth/types.d.ts.map +1 -1
  22. package/dist/contexts/metaContext/index.d.cts +18 -0
  23. package/dist/contexts/metaContext/index.d.cts.map +1 -0
  24. package/dist/contexts/metaContext/index.d.mts +18 -0
  25. package/dist/contexts/metaContext/index.d.mts.map +18 -0
  26. package/dist/contexts/metaContext/index.d.ts +18 -0
  27. package/dist/contexts/metaContext/index.d.ts.map +1 -0
  28. package/dist/hooks/auth/index.d.cts +1 -0
  29. package/dist/hooks/auth/index.d.cts.map +1 -1
  30. package/dist/hooks/auth/index.d.mts +1 -0
  31. package/dist/hooks/auth/index.d.mts.map +1 -0
  32. package/dist/hooks/auth/index.d.ts +1 -0
  33. package/dist/hooks/auth/index.d.ts.map +1 -1
  34. package/dist/hooks/router/use-link/index.d.cts +1 -1
  35. package/dist/hooks/router/use-link/index.d.mts +1 -1
  36. package/dist/hooks/router/use-link/index.d.mts.map +1 -1
  37. package/dist/hooks/router/use-link/index.d.ts +1 -1
  38. package/dist/hooks/useMeta/index.d.cts +2 -12
  39. package/dist/hooks/useMeta/index.d.cts.map +1 -1
  40. package/dist/hooks/useMeta/index.d.mts +2 -12
  41. package/dist/hooks/useMeta/index.d.mts.map +2 -12
  42. package/dist/hooks/useMeta/index.d.ts +2 -12
  43. package/dist/hooks/useMeta/index.d.ts.map +1 -1
  44. package/dist/index.cjs +18 -18
  45. package/dist/index.cjs.map +1 -1
  46. package/dist/index.d.cts +1 -0
  47. package/dist/index.d.cts.map +1 -1
  48. package/dist/index.d.mts +1 -0
  49. package/dist/index.d.mts.map +1 -0
  50. package/dist/index.d.ts +1 -0
  51. package/dist/index.d.ts.map +1 -1
  52. package/dist/index.mjs +18 -18
  53. package/dist/index.mjs.map +1 -1
  54. package/package.json +1 -1
  55. package/src/components/link/index.tsx +6 -8
  56. package/src/components/pages/auth/components/forgotPassword/index.tsx +2 -1
  57. package/src/components/pages/auth/components/login/index.tsx +3 -1
  58. package/src/components/pages/auth/components/register/index.tsx +3 -1
  59. package/src/components/pages/auth/components/updatePassword/index.tsx +2 -0
  60. package/src/components/pages/auth/types.tsx +8 -0
  61. package/src/contexts/metaContext/index.tsx +45 -0
  62. package/src/hooks/auth/index.ts +1 -0
  63. package/src/hooks/useMeta/index.ts +16 -2
  64. package/src/index.tsx +5 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@refinedev/core",
3
- "version": "4.55.0",
3
+ "version": "4.56.0",
4
4
  "private": false,
5
5
  "description": "refine is a React-based framework for building internal tools, rapidly. It ships with Ant Design System, an enterprise-level UI toolkit.",
6
6
  "repository": {
@@ -13,9 +13,7 @@ type LinkPropsWithTo = {
13
13
  };
14
14
 
15
15
  export type LinkProps<TProps = {}> = React.PropsWithChildren<
16
- (LinkPropsWithGo | LinkPropsWithTo) &
17
- React.AnchorHTMLAttributes<HTMLAnchorElement> &
18
- TProps
16
+ (LinkPropsWithGo | LinkPropsWithTo) & TProps
19
17
  >;
20
18
 
21
19
  /**
@@ -25,7 +23,7 @@ export type LinkProps<TProps = {}> = React.PropsWithChildren<
25
23
  */
26
24
  const LinkComponent = <TProps = {}>(
27
25
  props: LinkProps<TProps>,
28
- ref: Ref<HTMLAnchorElement>,
26
+ ref: Ref<Element>,
29
27
  ) => {
30
28
  const routerContext = useContext(RouterContext);
31
29
  const LinkFromContext = routerContext?.Link;
@@ -33,9 +31,6 @@ const LinkComponent = <TProps = {}>(
33
31
  const goFunction = useGo();
34
32
 
35
33
  let resolvedTo = "";
36
- if ("to" in props) {
37
- resolvedTo = props.to;
38
- }
39
34
  if ("go" in props) {
40
35
  if (!routerContext?.go) {
41
36
  warnOnce(
@@ -45,6 +40,9 @@ const LinkComponent = <TProps = {}>(
45
40
  }
46
41
  resolvedTo = goFunction({ ...props.go, type: "path" }) as string;
47
42
  }
43
+ if ("to" in props) {
44
+ resolvedTo = props.to;
45
+ }
48
46
 
49
47
  if (LinkFromContext) {
50
48
  return (
@@ -70,5 +68,5 @@ const LinkComponent = <TProps = {}>(
70
68
  };
71
69
 
72
70
  export const Link = forwardRef(LinkComponent) as <T = {}>(
73
- props: LinkProps<T> & { ref?: Ref<HTMLAnchorElement> },
71
+ props: LinkProps<T> & { ref?: Ref<Element> },
74
72
  ) => ReturnType<typeof LinkComponent>;
@@ -27,6 +27,7 @@ export const ForgotPasswordPage: React.FC<ForgotPasswordProps> = ({
27
27
  renderContent,
28
28
  formProps,
29
29
  title = undefined,
30
+ mutationVariables,
30
31
  }) => {
31
32
  const translate = useTranslate();
32
33
  const routerType = useRouterType();
@@ -53,7 +54,7 @@ export const ForgotPasswordPage: React.FC<ForgotPasswordProps> = ({
53
54
  <form
54
55
  onSubmit={(e) => {
55
56
  e.preventDefault();
56
- forgotPassword({ email });
57
+ forgotPassword({ ...mutationVariables, email });
57
58
  }}
58
59
  {...formProps}
59
60
  >
@@ -25,6 +25,7 @@ export const LoginPage: React.FC<LoginProps> = ({
25
25
  formProps,
26
26
  title = undefined,
27
27
  hideForm,
28
+ mutationVariables,
28
29
  }) => {
29
30
  const routerType = useRouterType();
30
31
  const Link = useLink();
@@ -62,6 +63,7 @@ export const LoginPage: React.FC<LoginProps> = ({
62
63
  <button
63
64
  onClick={() =>
64
65
  login({
66
+ ...mutationVariables,
65
67
  providerName: provider.name,
66
68
  })
67
69
  }
@@ -91,7 +93,7 @@ export const LoginPage: React.FC<LoginProps> = ({
91
93
  <form
92
94
  onSubmit={(e) => {
93
95
  e.preventDefault();
94
- login({ email, password, remember });
96
+ login({ ...mutationVariables, email, password, remember });
95
97
  }}
96
98
  {...formProps}
97
99
  >
@@ -28,6 +28,7 @@ export const RegisterPage: React.FC<RegisterProps> = ({
28
28
  formProps,
29
29
  title = undefined,
30
30
  hideForm,
31
+ mutationVariables,
31
32
  }) => {
32
33
  const routerType = useRouterType();
33
34
  const Link = useLink();
@@ -64,6 +65,7 @@ export const RegisterPage: React.FC<RegisterProps> = ({
64
65
  <button
65
66
  onClick={() =>
66
67
  register({
68
+ ...mutationVariables,
67
69
  providerName: provider.name,
68
70
  })
69
71
  }
@@ -93,7 +95,7 @@ export const RegisterPage: React.FC<RegisterProps> = ({
93
95
  <form
94
96
  onSubmit={(e) => {
95
97
  e.preventDefault();
96
- register({ email, password });
98
+ register({ ...mutationVariables, email, password });
97
99
  }}
98
100
  {...formProps}
99
101
  >
@@ -21,6 +21,7 @@ export const UpdatePasswordPage: React.FC<UpdatePasswordProps> = ({
21
21
  renderContent,
22
22
  formProps,
23
23
  title = undefined,
24
+ mutationVariables,
24
25
  }) => {
25
26
  const translate = useTranslate();
26
27
 
@@ -43,6 +44,7 @@ export const UpdatePasswordPage: React.FC<UpdatePasswordProps> = ({
43
44
  onSubmit={(e) => {
44
45
  e.preventDefault();
45
46
  updatePassword({
47
+ ...mutationVariables,
46
48
  password: newPassword,
47
49
  confirmPassword,
48
50
  });
@@ -144,6 +144,10 @@ export type AuthPageProps<
144
144
  * @optional
145
145
  * */
146
146
  title?: React.ReactNode;
147
+ /**
148
+ * @description Can be used to pass additional variables to the mutation. This is useful when you need to pass other variables to the authProvider.
149
+ */
150
+ mutationVariables?: Record<string, any>;
147
151
  };
148
152
 
149
153
  /**
@@ -167,6 +171,7 @@ export type LoginPageProps<
167
171
  formProps?: TFormProps;
168
172
  title?: React.ReactNode;
169
173
  hideForm?: boolean;
174
+ mutationVariables?: Record<string, unknown>;
170
175
  }>;
171
176
 
172
177
  /**
@@ -188,6 +193,7 @@ export type RegisterPageProps<
188
193
  formProps?: TFormProps;
189
194
  title?: React.ReactNode;
190
195
  hideForm?: boolean;
196
+ mutationVariables?: Record<string, unknown>;
191
197
  }>;
192
198
 
193
199
  /**
@@ -207,6 +213,7 @@ export type ForgotPasswordPageProps<
207
213
  contentProps?: TContentProps;
208
214
  formProps?: TFormProps;
209
215
  title?: React.ReactNode;
216
+ mutationVariables?: Record<string, unknown>;
210
217
  }>;
211
218
 
212
219
  /**
@@ -225,4 +232,5 @@ export type UpdatePasswordPageProps<
225
232
  contentProps?: TContentProps;
226
233
  formProps?: TFormProps;
227
234
  title?: React.ReactNode;
235
+ mutationVariables?: Record<string, unknown>;
228
236
  }>;
@@ -0,0 +1,45 @@
1
+ import React, {
2
+ type ReactNode,
3
+ createContext,
4
+ useContext,
5
+ useMemo,
6
+ } from "react";
7
+
8
+ type MetaContextValue = Record<string, any>;
9
+
10
+ export const MetaContext = createContext<MetaContextValue>({});
11
+
12
+ /**
13
+ * Is used to provide meta data to the children components.
14
+ * @internal
15
+ */
16
+ export const MetaContextProvider = ({
17
+ children,
18
+ value,
19
+ }: { children: ReactNode; value: MetaContextValue }) => {
20
+ const currentValue = useMetaContext();
21
+
22
+ const metaContext = useMemo(() => {
23
+ return {
24
+ ...currentValue,
25
+ ...value,
26
+ };
27
+ }, [currentValue, value]);
28
+
29
+ return (
30
+ <MetaContext.Provider value={metaContext}>{children}</MetaContext.Provider>
31
+ );
32
+ };
33
+
34
+ /**
35
+ * @internal
36
+ * @returns The MetaContext value.
37
+ */
38
+ export const useMetaContext = () => {
39
+ const context = useContext(MetaContext);
40
+ if (!context) {
41
+ throw new Error("useMetaContext must be used within a MetaContextProvider");
42
+ }
43
+
44
+ return useContext(MetaContext);
45
+ };
@@ -8,3 +8,4 @@ export { useUpdatePassword } from "./useUpdatePassword";
8
8
  export { useAuthenticated, useIsAuthenticated } from "./useIsAuthenticated";
9
9
  export { useCheckError, useOnError } from "./useOnError";
10
10
  export { useIsExistAuthentication } from "./useIsExistAuthentication";
11
+ export { useInvalidateAuthStore } from "./useInvalidateAuthStore";
@@ -1,3 +1,4 @@
1
+ import { useMetaContext } from "@contexts/metaContext";
1
2
  import { sanitizeResource } from "@definitions/helpers/sanitize-resource";
2
3
  import { useParsed } from "@hooks/router";
3
4
 
@@ -6,12 +7,14 @@ import type { IResourceItem } from "../../contexts/resource/types";
6
7
 
7
8
  /**
8
9
  * Hook that returns a function to get meta.
9
- * The meta is a combination of the resource meta, hook meta and query params.
10
+ * The meta is a combination of the resource meta, hook meta, query params and metaContext value.
10
11
  * @internal
11
12
  */
12
13
  export const useMeta = () => {
13
14
  const { params } = useParsed();
14
15
 
16
+ const metaContext = useMetaContext();
17
+
15
18
  const getMetaFn = ({
16
19
  resource,
17
20
  meta: metaFromProp,
@@ -30,7 +33,18 @@ export const useMeta = () => {
30
33
  ...additionalParams
31
34
  } = params ?? {};
32
35
 
33
- return { ...meta, ...additionalParams, ...metaFromProp };
36
+ const result: Record<string, unknown> = {
37
+ ...meta,
38
+ ...additionalParams,
39
+ ...metaFromProp,
40
+ };
41
+
42
+ // when MultiTenancyProvider from "@refinedev-ee/multi-tenancy" is provided, we need to add tenantId to the meta
43
+ if (metaContext?.tenantId) {
44
+ result["tenantId"] = metaContext.tenantId;
45
+ }
46
+
47
+ return result;
34
48
  };
35
49
 
36
50
  return getMetaFn;
package/src/index.tsx CHANGED
@@ -224,3 +224,8 @@ export {
224
224
  } from "./contexts/undoableQueue/types.js";
225
225
 
226
226
  export { IUnsavedWarnContext } from "./contexts/unsavedWarn/types.js";
227
+
228
+ export {
229
+ MetaContextProvider,
230
+ useMetaContext,
231
+ } from "./contexts/metaContext/index.js";