-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
auth/profile: Changes for corporate profiles
- Person's data is now prefetched to prevent any layout shifts and errors until person's data has been loaded. - Added new tab to summarize Affiliate's data which includes, as well as to cancel any guaranteed donations
- Loading branch information
1 parent
f0d8d67
commit dcf4f17
Showing
17 changed files
with
463 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { useSession } from 'next-auth/react' | ||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query' | ||
import { endpoints } from 'service/apiEndpoints' | ||
import { authQueryFnFactory } from 'service/restRequests' | ||
import { AlertStore } from 'stores/AlertStore' | ||
import { useTranslation } from 'react-i18next' | ||
import { DonationResponse } from 'gql/donations' | ||
import { AxiosError, AxiosResponse } from 'axios' | ||
import { | ||
AffiliateResponse, | ||
AffiliateWithDonationResponse, | ||
CancelAffiliateDonation, | ||
} from 'gql/affiliate' | ||
import { cancelAffiliateDonation, joinAffiliateProgram } from 'service/affiliate' | ||
|
||
export function useGetAffiliateData() { | ||
const { data: session } = useSession() | ||
return useQuery<AffiliateWithDonationResponse>( | ||
[endpoints.affiliate.getData.url], | ||
authQueryFnFactory<AffiliateWithDonationResponse>(session?.accessToken), | ||
) | ||
} | ||
|
||
export function useJoinAffiliateProgramMutation() { | ||
const { t } = useTranslation() | ||
const mutation = useMutation<AxiosResponse<AffiliateResponse>>([endpoints.affiliate.join], { | ||
mutationFn: joinAffiliateProgram, | ||
onError: () => AlertStore.show(t('common:alerts.error'), 'error'), | ||
onSuccess: () => AlertStore.show(t('common:alerts.message-sent'), 'success'), | ||
}) | ||
return mutation | ||
} | ||
|
||
export function useCancelGuaranteedDonationMutation() { | ||
const queryClient = useQueryClient() | ||
const { t } = useTranslation() | ||
const mutation = useMutation< | ||
AxiosResponse<DonationResponse>, | ||
AxiosError<DonationResponse>, | ||
CancelAffiliateDonation | ||
>({ | ||
mutationFn: (data) => cancelAffiliateDonation(data), | ||
onError: () => AlertStore.show(t('common:alerts.error'), 'error'), | ||
onSuccess: () => { | ||
AlertStore.show(t('common:alerts.message-sent'), 'success') | ||
queryClient.invalidateQueries({ queryKey: [endpoints.affiliate.getData.url] }) | ||
}, | ||
}) | ||
return mutation | ||
} |
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.