-
Notifications
You must be signed in to change notification settings - Fork 422
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: rtk segment identities (#5121)
- Loading branch information
Showing
12 changed files
with
261 additions
and
251 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { Res } from 'common/types/responses' | ||
import { Req } from 'common/types/requests' | ||
import { service } from 'common/service' | ||
import Utils from 'common/utils/utils' | ||
import transformCorePaging from 'common/transformCorePaging' | ||
import { sortBy } from 'lodash' | ||
|
||
export const identitySegmentService = service | ||
.enhanceEndpoints({ addTagTypes: ['IdentitySegment'] }) | ||
.injectEndpoints({ | ||
endpoints: (builder) => ({ | ||
getIdentitySegments: builder.query< | ||
Res['identitySegments'], | ||
Req['getIdentitySegments'] | ||
>({ | ||
providesTags: (res) => [{ id: res?.id, type: 'IdentitySegment' }], | ||
query: ({ projectId, ...query }: Req['getIdentitySegments']) => ({ | ||
url: `/projects/${projectId}/segments/?${Utils.toParam(query)}`, | ||
}), | ||
transformResponse: ( | ||
res: Res['identitySegments'], | ||
_, | ||
req: Req['getIdentitySegments'], | ||
) => | ||
transformCorePaging(req, { | ||
...res, | ||
results: sortBy(res.results, 'name'), | ||
}), | ||
}), | ||
// END OF ENDPOINTS | ||
}), | ||
}) | ||
|
||
export async function getIdentitySegments( | ||
store: any, | ||
data: Req['getIdentitySegments'], | ||
options?: Parameters< | ||
typeof identitySegmentService.endpoints.getIdentitySegments.initiate | ||
>[1], | ||
) { | ||
return store.dispatch( | ||
identitySegmentService.endpoints.getIdentitySegments.initiate( | ||
data, | ||
options, | ||
), | ||
) | ||
} | ||
// END OF FUNCTION_EXPORTS | ||
|
||
export const { | ||
useGetIdentitySegmentsQuery, | ||
// END OF EXPORTS | ||
} = identitySegmentService | ||
|
||
/* Usage examples: | ||
const { data, isLoading } = useGetIdentitySegmentsQuery({ id: 2 }, {}) //get hook | ||
const [createIdentitySegments, { isLoading, data, isSuccess }] = useCreateIdentitySegmentsMutation() //create hook | ||
identitySegmentService.endpoints.getIdentitySegments.select({id: 2})(store.getState()) //access data from any function | ||
*/ |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.