generated from vtex-apps/service-example
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from vtex/FIX-validator-loading
FIX / Profile Validator loading added
- Loading branch information
Showing
3 changed files
with
34 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,48 @@ | ||
import React, { useEffect, useMemo, useState } from 'react' | ||
import React, { useMemo } from 'react' | ||
import type { FC } from 'react' | ||
import { useOrderForm } from 'vtex.order-manager/OrderForm' | ||
import { Spinner } from 'vtex.styleguide' | ||
|
||
import useAffiliate from './context/useAffiliate' | ||
import { getSlugStoreFront } from './utils/shared' | ||
|
||
type Props = { | ||
Invalid: React.ComponentType | ||
Valid: React.ComponentType | ||
Invalid: React.FC | ||
Valid: React.FC | ||
} | ||
|
||
const AffiliateProfileValidator: FC<Props> = ({ Valid, Invalid }) => { | ||
const [valid, setValid] = useState(false) | ||
const affiliate = useAffiliate() | ||
const slug = useMemo(() => { | ||
return getSlugStoreFront() | ||
}, []) | ||
|
||
useEffect(() => { | ||
setValid(affiliate?.affiliate?.slug === slug) | ||
const { orderForm } = useOrderForm() | ||
|
||
const loading = useMemo(() => { | ||
return ( | ||
orderForm?.clientProfileData === undefined || | ||
affiliate.affiliateOrdersLoading | ||
) | ||
}, [orderForm, affiliate]) | ||
|
||
const isValid = useMemo(() => { | ||
return affiliate?.affiliate?.slug === slug | ||
}, [affiliate, slug]) | ||
|
||
return <div>{valid ? <Valid /> : <Invalid />}</div> | ||
if (loading) { | ||
return ( | ||
<div className="justify-center-s flex-s pa9-s"> | ||
<Spinner /> | ||
</div> | ||
) | ||
} | ||
|
||
if (isValid) { | ||
return <Valid /> | ||
} | ||
|
||
return <Invalid /> | ||
} | ||
|
||
export default AffiliateProfileValidator |
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