Skip to content

Commit

Permalink
refactor: add loading state for publisher consents
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristiaanScheermeijer committed Feb 9, 2024
1 parent 24dde0b commit 9266111
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/common/src/controllers/AccountController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,10 @@ export default class AccountController {
getPublisherConsents = async () => {
const { config } = useConfigStore.getState();

useAccountStore.setState({ loading: true });
useAccountStore.setState({ publisherConsentsLoading: true });
const consents = await this.accountService.getPublisherConsents(config);

useAccountStore.setState({ publisherConsents: consents, loading: false });
useAccountStore.setState({ publisherConsents: consents, publisherConsentsLoading: false });
};

getCaptureStatus = async (): Promise<GetCaptureStatusResponse> => {
Expand Down
2 changes: 2 additions & 0 deletions packages/common/src/stores/AccountStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type AccountStore = {
activePayment: PaymentDetail | null;
customerConsents: CustomerConsent[] | null;
publisherConsents: CustomFormField[] | null;
publisherConsentsLoading: boolean;
pendingOffer: Offer | null;
setLoading: (loading: boolean) => void;
getAccountInfo: () => { customerId: string; customer: Customer; customerConsents: CustomerConsent[] | null };
Expand All @@ -25,6 +26,7 @@ export const useAccountStore = createStore<AccountStore>('AccountStore', (set, g
activePayment: null,
customerConsents: null,
publisherConsents: null,
publisherConsentsLoading: false,
pendingOffer: null,
setLoading: (loading: boolean) => set({ loading }),
getAccountInfo: () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ const Registration = () => {
const [consentValues, setConsentValues] = useState<Record<string, string | boolean>>({});
const [consentErrors, setConsentErrors] = useState<string[]>([]);

const { publisherConsents, loading } = useAccountStore(({ publisherConsents, loading }) => ({ publisherConsents, loading }));
const { publisherConsents, publisherConsentsLoading, loading } = useAccountStore(({ publisherConsents, publisherConsentsLoading, loading }) => ({
publisherConsents,
publisherConsentsLoading,
loading,
}));

const handleChangeConsent: ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement> = ({ currentTarget }) => {
if (!currentTarget) return;
Expand Down Expand Up @@ -84,7 +88,7 @@ const Registration = () => {
submitting={submitting}
consentValues={consentValues}
publisherConsents={publisherConsents}
loading={loading}
loading={loading || publisherConsentsLoading}
canSubmit={!!values.email && !!values.password}
/>
);
Expand Down

0 comments on commit 9266111

Please sign in to comment.