-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(subscriber): Implement patch subscriber functionality and update…
… UI components
- Loading branch information
1 parent
8c083f7
commit 4d24095
Showing
6 changed files
with
110 additions
and
10 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { patchSubscriber } from '@/api/subscribers'; | ||
import { useEnvironment } from '@/context/environment/hooks'; | ||
import { QueryKeys } from '@/utils/query-keys'; | ||
import { OmitEnvironmentFromParameters } from '@/utils/types'; | ||
import type { IGetSubscriberResponseDto } from '@novu/shared'; | ||
import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'; | ||
|
||
type PatchSubscriberParameters = OmitEnvironmentFromParameters<typeof patchSubscriber>; | ||
|
||
export const usePatchSubscriber = ( | ||
options?: UseMutationOptions<IGetSubscriberResponseDto, unknown, PatchSubscriberParameters> | ||
) => { | ||
const queryClient = useQueryClient(); | ||
const { currentEnvironment } = useEnvironment(); | ||
|
||
const { mutateAsync, ...rest } = useMutation({ | ||
mutationFn: (args: PatchSubscriberParameters) => patchSubscriber({ environment: currentEnvironment!, ...args }), | ||
...options, | ||
onSuccess: async (data, variables, ctx) => { | ||
await queryClient.invalidateQueries({ | ||
queryKey: [QueryKeys.fetchSubscribers], | ||
}); | ||
|
||
await queryClient.invalidateQueries({ | ||
queryKey: [QueryKeys.fetchSubscriber], | ||
}); | ||
|
||
options?.onSuccess?.(data, variables, ctx); | ||
}, | ||
}); | ||
|
||
return { | ||
...rest, | ||
patchSubscriber: mutateAsync, | ||
}; | ||
}; |
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 |
---|---|---|
@@ -1,10 +1,17 @@ | ||
import { SubscriberDrawer } from '@/components/subscribers/subscriber-drawer'; | ||
import SubscriberTabs from '@/components/subscribers/subscriber-tabs'; | ||
import { useParams } from 'react-router-dom'; | ||
|
||
export function EditSubscriberPage() { | ||
const { subscriberId } = useParams<{ subscriberId: string }>(); | ||
|
||
if (!subscriberId) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<SubscriberDrawer open> | ||
<SubscriberTabs /> | ||
<SubscriberTabs subscriberId={subscriberId} /> | ||
</SubscriberDrawer> | ||
); | ||
} |