Skip to content

Commit

Permalink
auth/profile: Changes for corporate profiles
Browse files Browse the repository at this point in the history
- 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
sashko9807 committed Nov 4, 2023
1 parent f0d8d67 commit dcf4f17
Show file tree
Hide file tree
Showing 17 changed files with 463 additions and 27 deletions.
22 changes: 21 additions & 1 deletion public/locales/bg/profile.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"header": "Личен профил",
"corporate-header": "Корпоративен профил",
"campaigns": "Подкрепени кампании",
"personalInfo": {
"index": "Лична информация",
Expand All @@ -13,8 +14,14 @@
"noBirthday": "не e наличен",
"delete": "изтриване на акаунт/ профил"
},
"corporateInfo": {
"index": "Корпоративни данни",
"name": "Име на компания",
"number": "БУЛСТАТ/ЕИК"
},
"donations": {
"index": "Дарения",
"donor": "Дарител",
"helpThanks": "благодарим за помощта Ви!",
"donateNow": "Подкрепи сега",
"totalDonations": "Всички дарения",
Expand All @@ -33,6 +40,8 @@
"sort": "Вид",
"cause": "Кауза",
"amount": "Сума",
"cancelDonation": "Откажи дарение",
"cancel": "Откажи",
"certificate": "Сертификат",
"download": "Свалете",
"lv": "лв",
Expand All @@ -43,7 +52,8 @@
"initial": "започнато",
"waiting": "чакащо",
"succeeded": "успешно",
"cancelled": "отменено"
"cancelled": "отменено",
"guaranteed": "гарантирано"
}
},
"certificates-history": {
Expand Down Expand Up @@ -112,5 +122,15 @@
"saveAccount": "Запази моя акаунт",
"disableAccount": "Изтрий моя акаунт",
"disabled": "Акаунтът Ви е изтрит."
},
"affiliate": {
"index": "Партньорска програма",
"join": "Включете се към програмата",
"data-summary": "Данни по партньорска програма",
"guaranteedDonationsList": "Списък с гарантирани дарения",
"code": "Код",
"status": "Статус",
"guaranteedDonations": "Гарантирани дарения(общо)",
"guaranteedAmount": "Гарантирана сума(общо)"
}
}
49 changes: 48 additions & 1 deletion public/locales/en/profile.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"header": "Personal profile",
"corporate-header": "Corporate Profile",
"personalInfo": {
"index": "Personal information",
"login": "Login information:",
Expand All @@ -12,8 +13,14 @@
"noBirthday": "not available",
"delete": "delete account/ profile"
},
"corporateInfo": {
"index": "Corporate information",
"name": "Corporate name",
"number": "BULSTAT/EIK"
},
"donations": {
"index": "Donations",
"donor": "Donor",
"helpThanks": "thank you for your help!",
"donateNow": "Donate now",
"totalDonations": "All donations",
Expand All @@ -28,6 +35,8 @@
"type": "Type",
"cause": "Cause",
"amount": "Amount",
"cancelDonation": "Cancel donation",
"cancel": "Cancel",
"certificate": "Certificate",
"download": "Download",
"lv": "lv",
Expand All @@ -36,7 +45,8 @@
"initial": "initial",
"waiting": "waiting",
"succeeded": "succeeded",
"cancelled": "cancelled"
"cancelled": "cancelled",
"guaranteed": "guaranteed"
}
},
"certificates-history": {
Expand All @@ -49,6 +59,33 @@
"noCampaigns": "You are not in organizer, coordinator or beneficiery role in any campaign",
"donatedTo": "Campaigns I donated to"
},
"myNotifications": {
"index": "My notifications",
"status-title": "Notification subscription status",
"status-msg": "Your subscription status is",
"modal": {
"title-subscribe": "Subscribe for receiving notifications from Podkrepi.bg",
"title-unsubscribe": "Unsubscribe for receiving notifications from Podkrepi.bg",
"campaign-title-unsubscribe": "Unsubscribe from receiving notifications from this campaign",
"cta": "Confirm",
"subscribe-msg": "You've successfully subscribed for receiving notifications",
"unsubscribe-msg": "You've successfully unsubscribed for receiving notifications",
"campaign-unsubscribe-msg": "You've successfully unsubscribed from receiving notifications regarding this campaign"
},
"status": {
"active": "Active",
"inactive": "Deactivated"
},
"cta": {
"activate": "Activate",
"deactivate": "Deactivate"
},
"campaign": {
"index": "Campaign notifications",
"noSubscriptions": "Към момента не сте се записали за получаване на известия по конкретни кампании",
"cta": "Unsubscribe"
}
},
"donationsContract": "Donation contract",
"certificates": "Certificates",
"birthdateModal": {
Expand Down Expand Up @@ -78,5 +115,15 @@
"saveAccount": "Save my account",
"disableAccount": "Delete my account",
"disabled": "Your account has been deleted."
},
"affiliate": {
"index": "Affiliate program",
"join": "Join the program",
"data-summary": "Affiliate program summary",
"guaranteedDonationsList": "List of guaranteed donations",
"code": "Code",
"status": "Status",
"guaranteedDonations": "Guaranteed donations(total)",
"guaranteedAmount": "Guaranteed amount(total)"
}
}
50 changes: 50 additions & 0 deletions src/common/hooks/affiliates.ts
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
}
1 change: 1 addition & 0 deletions src/common/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export const routes = {
myCampaigns: '/profile/my-campaigns',
recurringDonations: '/profile/recurring-donations',
myNotifications: '/profile/my-notifications',
affiliateProgram: '/profile/affiliate-program',
},
register: '/register',
aboutProject: '/about-project',
Expand Down
Loading

0 comments on commit dcf4f17

Please sign in to comment.