diff --git a/.github/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md index 81efaa9..79e1897 100644 --- a/.github/CODE_OF_CONDUCT.md +++ b/.github/CODE_OF_CONDUCT.md @@ -55,7 +55,7 @@ further defined and clarified by project maintainers. #### Enforcement Instances of abusive, harassing, or otherwise unacceptable behavior may be -reported by contacting the project team at [Moon team](mailto:amen.souissi@decathlon.com). All complaints will be reviewed and investigated and will result in a response that +reported by contacting the project team at [Moon team](mailto:amen.souissi@pricemoov-oss.com). All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f675410..a76fd2c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,4 +1,4 @@ -## Contributing to @decathlon/moon +## Contributing to @pricemoov-oss/moon First off, thanks for taking the time to contribute! diff --git a/LICENSE b/LICENSE index 8f50791..3f7f71e 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright 2020 Decathlon + Copyright 2020 PricemoovOSS Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/README.md b/README.md index e9fba58..e16027d 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ Table of contents Installation for Axios client ============================ ```bash -npm install @decathlon/moon @decathlon/moon-axios react-query axios --save +npm install @pricemoov-oss/moon @pricemoov-oss/moon-axios react-query axios --save ``` @@ -54,12 +54,12 @@ Usage You get started by create REST links. A link is an object which need an id and an HTTP client config like the AxiosConfig (that extends the Moon's ClientConfig) of your REST server (for more information about the REST link config please see the **Moon config** section). -To connect Moon to your React app, you will need to use the MoonProvider component exported from `@decathlon/moon`. The MoonProvider is a React's Context.Provider. It wraps your React app and places the client and the store (the query cache of the **react-query**) on the context, which allows you to access it from anywhere in your component tree. You also need to add the HTTP client factory (**clientFactory**). Here we have added the Axios factory to create an axios client for each link. You can also add a client factory for each link. This is useful for using multiple data sources or for mocking data during development phase (tests, mvp...). +To connect Moon to your React app, you will need to use the MoonProvider component exported from `@pricemoov-oss/moon`. The MoonProvider is a React's Context.Provider. It wraps your React app and places the client and the store (the query cache of the **react-query**) on the context, which allows you to access it from anywhere in your component tree. You also need to add the HTTP client factory (**clientFactory**). Here we have added the Axios factory to create an axios client for each link. You can also add a client factory for each link. This is useful for using multiple data sources or for mocking data during development phase (tests, mvp...). ```js -import { MoonProvider } from "@decathlon/moon"; -import axiosClientFactory from "@decathlon/moon-axios"; +import { MoonProvider } from "@pricemoov-oss/moon"; +import axiosClientFactory from "@pricemoov-oss/moon-axios"; const links = [ { @@ -85,7 +85,7 @@ Query ----- ```js -import { Query } from "@decathlon/moon"; +import { Query } from "@pricemoov-oss/moon"; const MyComponent = () => { return ( @@ -112,7 +112,7 @@ useQuery The same query with the **useQuery** hook ```js -import { useQuery } from "@decathlon/moon"; +import { useQuery } from "@pricemoov-oss/moon"; const MyComponent = () => { const [{ isLoading, error }, { refetch }] = useQuery({ @@ -136,7 +136,7 @@ usePrefetchQuery If you're lucky enough, you may know enough about what your users will do to be able to prefetch the data they need before it's needed! If this is the case, you can use the usePrefetchQuery hook. This hook return a prefetch function to prefetch the results of a query to be placed into the cache: ```js -import { usePrefetchQuery } from "@decathlon/moon"; +import { usePrefetchQuery } from "@pricemoov-oss/moon"; const MyComponent = ({page}) => { const prefetchQuery = usePrefetchQuery({ @@ -156,7 +156,7 @@ useInfiniteQuery --------------- ```js -import { useInfiniteQuery } from "@decathlon/moon"; +import { useInfiniteQuery } from "@pricemoov-oss/moon"; interface QueryData { comments: any; @@ -200,7 +200,7 @@ Mutation useMutation Now that we've learned how to fetch data with the Query/useQuery component/hook, the next step is to learn how to mutate that data with mutations. For that we need to use the Mutation/useMutation component/hook. ```js -import { Mutation } from '@decathlon/moon'; +import { Mutation } from '@pricemoov-oss/moon'; const MyComponent = () => { return ( @@ -217,7 +217,7 @@ const MyComponent = () => { The same mutation with **useMutation**: ```js -import { useMutation } from '@decathlon/moon'; +import { useMutation } from '@pricemoov-oss/moon'; const MyComponent = () => { const [{ error, data }, { mutate }] = useMutation({ @@ -245,7 +245,7 @@ useQueryState Updated when the query state is changed. The optional **stateToProps** function is used for selecting the part of the data from the query state that the connected component needs. ```js -import { useQueryState } from '@decathlon/moon'; +import { useQueryState } from '@pricemoov-oss/moon'; const MyComponent = () => { const stateToProps = (queryState) => queryState // optional @@ -258,7 +258,7 @@ const MyComponent = () => { The first prop is the query id used by the query. If the query is defined without an id then the id generated by default must be used. To generate an identifier, you must use the **getQueryId** utility. The default id is generated from the source, the endPoint and the variables props of the query. ```js -import { useQueryState, getQueryId } from "@decathlon/moon"; +import { useQueryState, getQueryId } from "@pricemoov-oss/moon"; const MyComponent = () => { const queryId = getQueryId({ source: "FOO", endPoint: "/users", variables: { foo: "bar" } }); @@ -274,7 +274,7 @@ useQueriesStates Updated when one of the query states is changed.The optional **statesToProps** function is used for selecting the part of the data from the query state that the connected component needs. ```js -import { useQueriesStates } from '@decathlon/moon'; +import { useQueriesStates } from '@pricemoov-oss/moon'; const MyComponent = () => { const statesToProps = (queriesStates) => queriesStates @@ -289,7 +289,7 @@ useQueryResult Updated only when the query result is changed. .The optional **resultToProps** function is used for selecting the part of the data from the query result that the connected component needs. ```js -import { useQueryResult } from '@decathlon/moon'; +import { useQueryResult } from '@pricemoov-oss/moon'; const MyComponent = () => { const resultToProps = (queryResult) => queryResult // optional @@ -305,7 +305,7 @@ useQueriesResults Updated only when one of the query results is changed. The optional **statesToProps** function is used for selecting the part of the data from the queries results that the connected component needs. ```js -import { useQueriesResults } from '@decathlon/moon'; +import { useQueriesResults } from '@pricemoov-oss/moon'; const MyComponent = () => { const resultsToProps = (queriesResults) => queriesResults @@ -319,7 +319,7 @@ useMoon You can use the moon client directly like this: ```js -import { useMoon } from '@decathlon/moon'; +import { useMoon } from '@pricemoov-oss/moon'; const MyComponent = () => { const { client, store } = useMoon(); @@ -338,7 +338,7 @@ withMoon Same as useMoon hook. ```js -import { withMoon } from '@decathlon/moon'; +import { withMoon } from '@pricemoov-oss/moon'; interface Props extends IMoonContextValue { prop: string; @@ -357,7 +357,7 @@ withQueryResult Same as useQueryResult hook. ```js -import { withQueryResult } from '@decathlon/moon'; +import { withQueryResult } from '@pricemoov-oss/moon'; interface Props { queryResult: QueryState; @@ -377,7 +377,7 @@ withQueriesResults Same as useQueriesResults hook. ```js -import { withQueriesResults } from '@decathlon/moon'; +import { withQueriesResults } from '@pricemoov-oss/moon'; interface Props { queriesResults: { @@ -497,7 +497,7 @@ For each Moon link we can add interceptors (middleware: language, api token, suc ```js import { AxiosRequestConfig } from "axios"; -import axiosClientFactory from "@decathlon/moon-axios"; +import axiosClientFactory from "@pricemoov-oss/moon-axios"; function successHandler(response: AxiosResponse){...}; @@ -569,8 +569,8 @@ up the merging process. * **Benjamin Wintrebert** [Ben-Wintrebert](https://github.com/Ben-Wintrebert) * **Hyacinthe Knobloch** [hyacintheknobloch](https://github.com/hyacintheknobloch) -See also the list of [contributors](https://github.com/Decathlon/moon/graphs/contributors) who participated in this project. +See also the list of [contributors](https://github.com/PricemoovOSS/moon/graphs/contributors) who participated in this project. ## License -This project is licensed under the Apache-2.0 License - see the [LICENSE.md](https://github.com/Decathlon/moon/blob/master/LICENSE) file for details +This project is licensed under the Apache-2.0 License - see the [LICENSE.md](https://github.com/PricemoovOSS/moon/blob/master/LICENSE) file for details diff --git a/packages/moon-axios/README.md b/packages/moon-axios/README.md index 3b12e9d..f007c1b 100644 --- a/packages/moon-axios/README.md +++ b/packages/moon-axios/README.md @@ -1,23 +1,23 @@ -# @decathlon/moon-axios +# @pricemoov-oss/moon-axios _**The power of react-query with Axios**_ -**@decathlon/moon** is the [Axios](https://github.com/axios/axios) HTTP client for [Moon](https://github.com/Decathlon/moon). +**@pricemoov-oss/moon** is the [Axios](https://github.com/axios/axios) HTTP client for [Moon](https://github.com/PricemoovOSS/moon). ## Installation ```bash -npm install @decathlon/moon @decathlon/moon-axios react-query axios --save +npm install @pricemoov-oss/moon @pricemoov-oss/moon-axios react-query axios --save ``` ## Usage -Please see the [Moon doc](https://github.com/Decathlon/moon/blob/master/README.md) for more details. +Please see the [Moon doc](https://github.com/PricemoovOSS/moon/blob/master/README.md) for more details. ```js import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios"; -import { MoonProvider, ILink } from "@decathlon/moon"; -import axiosClientFactory from "@decathlon/moon-axios"; +import { MoonProvider, ILink } from "@pricemoov-oss/moon"; +import axiosClientFactory from "@pricemoov-oss/moon-axios"; function successHandler(response: AxiosResponse){...}; diff --git a/packages/moon-axios/package.json b/packages/moon-axios/package.json index 5534e6c..1d66325 100644 --- a/packages/moon-axios/package.json +++ b/packages/moon-axios/package.json @@ -1,8 +1,8 @@ { - "name": "@decathlon/moon-axios", + "name": "@pricemoov-oss/moon-axios", "version": "1.0.3", "description": "Axios for moon", - "author": "Decathlon", + "author": "PricemoovOSS", "license": "Apache-2.0", "main": "lib/moon-axios/src/index.js", "module": "dist/index.es.js", @@ -10,12 +10,12 @@ "types": "dist/index.d.ts", "repository": { "type": "git", - "url": "git+https://github.com/Decathlon/moon.git" + "url": "git+https://github.com/PricemoovOSS/moon.git" }, "bugs": { - "url": "https://github.com/Decathlon/moon/issues" + "url": "https://github.com/PricemoovOSS/moon/issues" }, - "homepage": "https://github.com/Decathlon/moon/blob/master/README.md", + "homepage": "https://github.com/PricemoovOSS/moon/blob/master/README.md", "files": [ "dist", "lib" @@ -24,11 +24,11 @@ "qs": "~6.9.4" }, "peerDependencies": { - "@decathlon/moon": "~3.0.0", + "@pricemoov-oss/moon": "~3.0.0", "axios": "~0.20.0" }, "devDependencies": { - "@decathlon/moon": "^3.0.0" + "@pricemoov-oss/moon": "^3.0.0" }, "scripts": { "build": "rimraf dist && rollup -c && npm run build:lib", diff --git a/packages/moon-axios/src/index.ts b/packages/moon-axios/src/index.ts index 09a2e5c..d37dd1f 100644 --- a/packages/moon-axios/src/index.ts +++ b/packages/moon-axios/src/index.ts @@ -1,6 +1,6 @@ import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse, AxiosInterceptorManager } from "axios"; import * as qs from "qs"; -import { IInterceptors, ClientInstance } from "@decathlon/moon"; +import { IInterceptors, ClientInstance } from "@pricemoov-oss/moon"; // eslint-disable-next-line @typescript-eslint/no-explicit-any const paramsSerializer = (params: any) => qs.stringify(params, { arrayFormat: "repeat" }); diff --git a/packages/moon-graphql/README.md b/packages/moon-graphql/README.md index 2db0a8e..03eef8e 100644 --- a/packages/moon-graphql/README.md +++ b/packages/moon-graphql/README.md @@ -1,22 +1,22 @@ -# @decathlon/moon-graphql +# @pricemoov-oss/moon-graphql _**The power of react-query with graphql**_ -**@decathlon/moon** is the [graphql](https://github.com/prisma-labs/graphql-request) HTTP client for [Moon](https://github.com/Decathlon/moon). +**@pricemoov-oss/moon** is the [graphql](https://github.com/prisma-labs/graphql-request) HTTP client for [Moon](https://github.com/PricemoovOSS/moon). ## Installation ```bash -npm install @decathlon/moon @decathlon/moon-graphql react-query graphql graphql-request --save +npm install @pricemoov-oss/moon @pricemoov-oss/moon-graphql react-query graphql graphql-request --save ``` ## Usage -Please see the [Moon doc](https://github.com/Decathlon/moon/blob/master/README.md) for more details. +Please see the [Moon doc](https://github.com/PricemoovOSS/moon/blob/master/README.md) for more details. ```js -import { MoonProvider, ILink } from "@decathlon/moon"; -import graphqlClientFactory from "@decathlon/moon-graphql"; +import { MoonProvider, ILink } from "@pricemoov-oss/moon"; +import graphqlClientFactory from "@pricemoov-oss/moon-graphql"; function successHandler(response){...}; diff --git a/packages/moon-graphql/package.json b/packages/moon-graphql/package.json index 4ccb85a..deb6d15 100644 --- a/packages/moon-graphql/package.json +++ b/packages/moon-graphql/package.json @@ -1,8 +1,8 @@ { - "name": "@decathlon/moon-graphql", + "name": "@pricemoov-oss/moon-graphql", "version": "1.0.1", "description": "GraphQL for moon", - "author": "Decathlon", + "author": "PricemoovOSS", "license": "Apache-2.0", "main": "lib/moon-graphql/src/index.js", "module": "dist/index.es.js", @@ -10,12 +10,12 @@ "types": "dist/index.d.ts", "repository": { "type": "git", - "url": "git+https://github.com/Decathlon/moon.git" + "url": "git+https://github.com/PricemoovOSS/moon.git" }, "bugs": { - "url": "https://github.com/Decathlon/moon/issues" + "url": "https://github.com/PricemoovOSS/moon/issues" }, - "homepage": "https://github.com/Decathlon/moon/blob/master/README.md", + "homepage": "https://github.com/PricemoovOSS/moon/blob/master/README.md", "files": [ "dist", "lib" @@ -24,12 +24,12 @@ "qs": "~6.9.4" }, "peerDependencies": { - "@decathlon/moon": "~3.0.0", + "@pricemoov-oss/moon": "~3.0.0", "graphql": "~15.3.0", "graphql-request": "~3.4.0" }, "devDependencies": { - "@decathlon/moon": "^3.0.0" + "@pricemoov-oss/moon": "^3.0.0" }, "scripts": { "build": "rimraf dist && rollup -c && npm run build:lib", diff --git a/packages/moon-graphql/src/index.ts b/packages/moon-graphql/src/index.ts index dcc9469..bdaa05f 100644 --- a/packages/moon-graphql/src/index.ts +++ b/packages/moon-graphql/src/index.ts @@ -1,6 +1,6 @@ import { GraphQLClient } from "graphql-request"; import { RequestInit } from "graphql-request/dist/types.dom"; -import { IInterceptors, ClientInstance } from "@decathlon/moon"; +import { IInterceptors, ClientInstance } from "@pricemoov-oss/moon"; export interface GraphQLRequestConfig { params?: Record; diff --git a/packages/moon/README.md b/packages/moon/README.md index b8ef7c7..98d8387 100644 --- a/packages/moon/README.md +++ b/packages/moon/README.md @@ -45,7 +45,7 @@ Table of contents Installation for Axios client ============================ ```bash -npm install @decathlon/moon @decathlon/moon-axios react-query axios --save +npm install @pricemoov-oss/moon @pricemoov-oss/moon-axios react-query axios --save ``` @@ -54,12 +54,12 @@ Usage You get started by create REST links. A link is an object which need an id and an HTTP client config like the AxiosConfig (that extends the Moon's ClientConfig) of your REST server (for more information about the REST link config please see the **Moon config** section). -To connect Moon to your React app, you will need to use the MoonProvider component exported from `@decathlon/moon`. The MoonProvider is a React's Context.Provider. It wraps your React app and places the client and the store (the query cache of the **react-query**) on the context, which allows you to access it from anywhere in your component tree. You also need to add the HTTP client factory (**clientFactory**). Here we have added the Axios factory to create an axios client for each link. You can also add a client factory for each link. This is useful for using multiple data sources or for mocking data during development phase (tests, mvp...). +To connect Moon to your React app, you will need to use the MoonProvider component exported from `@pricemoov-oss/moon`. The MoonProvider is a React's Context.Provider. It wraps your React app and places the client and the store (the query cache of the **react-query**) on the context, which allows you to access it from anywhere in your component tree. You also need to add the HTTP client factory (**clientFactory**). Here we have added the Axios factory to create an axios client for each link. You can also add a client factory for each link. This is useful for using multiple data sources or for mocking data during development phase (tests, mvp...). ```js -import { MoonProvider } from "@decathlon/moon"; -import axiosClientFactory from "@decathlon/moon-axios"; +import { MoonProvider } from "@pricemoov-oss/moon"; +import axiosClientFactory from "@pricemoov-oss/moon-axios"; const links = [ { @@ -85,7 +85,7 @@ Query ----- ```js -import { Query } from "@decathlon/moon"; +import { Query } from "@pricemoov-oss/moon"; const MyComponent = () => { return ( @@ -112,7 +112,7 @@ useQuery The same query with the **useQuery** hook ```js -import { useQuery } from "@decathlon/moon"; +import { useQuery } from "@pricemoov-oss/moon"; const MyComponent = () => { const [{ isLoading, error }, { refetch }] = useQuery({ @@ -136,7 +136,7 @@ usePrefetchQuery If you're lucky enough, you may know enough about what your users will do to be able to prefetch the data they need before it's needed! If this is the case, you can use the usePrefetchQuery hook. This hook return a prefetch function to prefetch the results of a query to be placed into the cache: ```js -import { usePrefetchQuery } from "@decathlon/moon"; +import { usePrefetchQuery } from "@pricemoov-oss/moon"; const MyComponent = ({page}) => { const prefetchQuery = usePrefetchQuery({ @@ -156,7 +156,7 @@ useInfiniteQuery --------------- ```js -import { useInfiniteQuery } from "@decathlon/moon"; +import { useInfiniteQuery } from "@pricemoov-oss/moon"; interface QueryData { comments: any; @@ -200,7 +200,7 @@ Mutation useMutation Now that we've learned how to fetch data with the Query/useQuery component/hook, the next step is to learn how to mutate that data with mutations. For that we need to use the Mutation/useMutation component/hook. ```js -import { Mutation } from '@decathlon/moon'; +import { Mutation } from '@pricemoov-oss/moon'; const MyComponent = () => { return ( @@ -217,7 +217,7 @@ const MyComponent = () => { The same mutation with **useMutation**: ```js -import { useMutation } from '@decathlon/moon'; +import { useMutation } from '@pricemoov-oss/moon'; const MyComponent = () => { const [{ error, data }, { mutate }] = useMutation({ @@ -245,7 +245,7 @@ useQueryState Updated when the query state is changed. The optional **stateToProps** function is used for selecting the part of the data from the query state that the connected component needs. ```js -import { useQueryState } from '@decathlon/moon'; +import { useQueryState } from '@pricemoov-oss/moon'; const MyComponent = () => { const stateToProps = (queryState) => queryState // optional @@ -258,7 +258,7 @@ const MyComponent = () => { The first prop is the query id used by the query. If the query is defined without an id then the id generated by default must be used. To generate an identifier, you must use the **getQueryId** utility. The default id is generated from the source, the endPoint and the variables props of the query. ```js -import { useQueryState, getQueryId } from "@decathlon/moon"; +import { useQueryState, getQueryId } from "@pricemoov-oss/moon"; const MyComponent = () => { const queryId = getQueryId({ source: "FOO", endPoint: "/users", variables: { foo: "bar" } }); @@ -274,7 +274,7 @@ useQueriesStates Updated when one of the query states is changed.The optional **statesToProps** function is used for selecting the part of the data from the query state that the connected component needs. ```js -import { useQueriesStates } from '@decathlon/moon'; +import { useQueriesStates } from '@pricemoov-oss/moon'; const MyComponent = () => { const statesToProps = (queriesStates) => queriesStates @@ -289,7 +289,7 @@ useQueryResult Updated only when the query result is changed. .The optional **resultToProps** function is used for selecting the part of the data from the query result that the connected component needs. ```js -import { useQueryResult } from '@decathlon/moon'; +import { useQueryResult } from '@pricemoov-oss/moon'; const MyComponent = () => { const resultToProps = (queryResult) => queryResult // optional @@ -305,7 +305,7 @@ useQueriesResults Updated only when one of the query results is changed. The optional **statesToProps** function is used for selecting the part of the data from the queries results that the connected component needs. ```js -import { useQueriesResults } from '@decathlon/moon'; +import { useQueriesResults } from '@pricemoov-oss/moon'; const MyComponent = () => { const resultsToProps = (queriesResults) => queriesResults @@ -319,7 +319,7 @@ useMoon You can use the moon client directly like this: ```js -import { useMoon } from '@decathlon/moon'; +import { useMoon } from '@pricemoov-oss/moon'; const MyComponent = () => { const { client, store } = useMoon(); @@ -338,7 +338,7 @@ withMoon Same as useMoon hook. ```js -import { withMoon } from '@decathlon/moon'; +import { withMoon } from '@pricemoov-oss/moon'; interface Props extends IMoonContextValue { prop: string; @@ -357,7 +357,7 @@ withQueryResult Same as useQueryResult hook. ```js -import { withQueryResult } from '@decathlon/moon'; +import { withQueryResult } from '@pricemoov-oss/moon'; interface Props { queryResult: QueryState; @@ -377,7 +377,7 @@ withQueriesResults Same as useQueriesResults hook. ```js -import { withQueriesResults } from '@decathlon/moon'; +import { withQueriesResults } from '@pricemoov-oss/moon'; interface Props { queriesResults: { @@ -497,7 +497,7 @@ For each Moon link we can add interceptors (middleware: language, api token, suc ```js import { AxiosRequestConfig } from "axios"; -import axiosClientFactory from "@decathlon/moon-axios"; +import axiosClientFactory from "@pricemoov-oss/moon-axios"; function successHandler(response: AxiosResponse){...}; @@ -569,8 +569,8 @@ up the merging process. * **Benjamin Wintrebert** [Ben-Wintrebert](https://github.com/Ben-Wintrebert) * **Hyacinthe Knobloch** [hyacintheknobloch](https://github.com/hyacintheknobloch) -See also the list of [contributors](https://github.com/Decathlon/moon/graphs/contributors) who participated in this project. +See also the list of [contributors](https://github.com/PricemoovOSS/moon/graphs/contributors) who participated in this project. ## License -This project is licensed under the Apache-2.0 License - see the [LICENSE.md](https://github.com/Decathlon/moon/blob/master/LICENSE) file for details +This project is licensed under the Apache-2.0 License - see the [LICENSE.md](https://github.com/PricemoovOSS/moon/blob/master/LICENSE) file for details diff --git a/packages/moon/package.json b/packages/moon/package.json index aa3d301..d21edd6 100644 --- a/packages/moon/package.json +++ b/packages/moon/package.json @@ -1,8 +1,8 @@ { - "name": "@decathlon/moon", - "version": "4.4.1", + "name": "@pricemoov-oss/moon", + "version": "4.5.0", "description": "A featured, production ready caching REST client for every React UI", - "author": "Decathlon", + "author": "PricemoovOSS", "license": "Apache-2.0", "main": "lib/index.js", "module": "dist/index.es.js", @@ -10,12 +10,12 @@ "types": "dist/index.d.ts", "repository": { "type": "git", - "url": "git+https://github.com/Decathlon/moon.git" + "url": "git+https://github.com/PricemoovOSS/moon.git" }, "bugs": { - "url": "https://github.com/Decathlon/moon/issues" + "url": "https://github.com/PricemoovOSS/moon/issues" }, - "homepage": "https://github.com/Decathlon/moon/blob/master/README.md", + "homepage": "https://github.com/PricemoovOSS/moon/blob/master/README.md", "files": [ "dist", "lib" diff --git a/packages/moon/src/useMutation.tsx b/packages/moon/src/useMutation.tsx index d643477..9c3fa8f 100644 --- a/packages/moon/src/useMutation.tsx +++ b/packages/moon/src/useMutation.tsx @@ -56,12 +56,14 @@ export default function useMutation< return client.mutate(source, endPoint, type, variables, options); } + const mutationFn = mutationConfig?.mutationFn || mutation; + const { mutate: reactQueryMutate, mutateAsync: reactQueryMutateAsync, reset, ...others } = useReactMutation< MutationResponse | undefined, MutationError, MutationVariables | undefined, unknown - >(mutation, mutationConfig); + >(mutationFn, mutationConfig); const mutate = React.useCallback(() => { return reactQueryMutate(variables); diff --git a/packages/moon/test/integration/mutation-hook.test.tsx b/packages/moon/test/integration/mutation-hook.test.tsx index e9d4181..bc41101 100644 --- a/packages/moon/test/integration/mutation-hook.test.tsx +++ b/packages/moon/test/integration/mutation-hook.test.tsx @@ -54,6 +54,50 @@ describe("Mutation hook with MoonProvider", () => { expect(onResponse).toBeCalledWith(data, { foo: "bar" }, undefined); }); + test("should call the mutate custom action", async () => { + const data = { + data: { status: true } + }; + const mutationFn = jest.fn().mockImplementation(() => Promise.resolve(data)); + const post = jest.fn(); + const clientFactory = getMockedClientFactory({ post }); + + const onResponse = jest.fn(); + const wrapper = ({ children }: { children?: any }) => ( + + {children} + + ); + const { result, waitForNextUpdate } = renderHook( + () => + useMutation({ + source: "FOO", + endPoint: "/users", + variables: { foo: "bar" }, + mutationConfig: { onSuccess: onResponse, mutationFn } + }), + { wrapper } + ); + act(() => { + const [{ data, error }, { mutate }] = result.current; + expect(data).toBeUndefined(); + expect(error).toBeNull(); + mutate(); + }); + let state = result.current[0]; + expect(state.data).toBeUndefined(); + expect(state.error).toBeNull(); + await waitForNextUpdate(); + state = result.current[0]; + expect(state.data).toBe(data); + expect(state.error).toBeNull(); + expect(post).toBeCalledTimes(0); + expect(mutationFn).toBeCalledTimes(1); + expect(mutationFn).toBeCalledWith({ foo: "bar" }); + expect(onResponse).toBeCalledTimes(1); + expect(onResponse).toBeCalledWith(data, { foo: "bar" }, undefined); + }); + test("should render an error", async () => { const error = "Bimm!"; const post = jest.fn().mockImplementation(() => Promise.reject(error)); diff --git a/tsconfig.json b/tsconfig.json index a061336..9f1daf2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -33,9 +33,9 @@ "esModuleInterop": true, "baseUrl": "./packages", "paths": { - "@decathlon/moon": ["moon/src"], - "@decathlon/moon-axios": ["moon-axios/src"], - "@decathlon/*": ["*/src"] + "@pricemoov-oss/moon": ["moon/src"], + "@pricemoov-oss/moon-axios": ["moon-axios/src"], + "@pricemoov-oss/*": ["*/src"] } }, "include": ["packages/**/*.ts"],