forked from LaconicNetwork/icns-frontend
Add loading state on primary button
This commit is contained in:
parent
7e72ab82b6
commit
a61856557c
@ -1,18 +1,36 @@
|
|||||||
import { ButtonHTMLAttributes, FunctionComponent } from "react";
|
import { ButtonHTMLAttributes, FunctionComponent } from "react";
|
||||||
import styled from "styled-components";
|
import styled, { keyframes } from "styled-components";
|
||||||
import color from "../../styles/color";
|
import color from "../../styles/color";
|
||||||
|
|
||||||
export const PrimaryButton: FunctionComponent<
|
interface PrimaryButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
||||||
ButtonHTMLAttributes<HTMLButtonElement>
|
isLoading?: boolean;
|
||||||
> = ({ children, ...props }) => {
|
}
|
||||||
|
|
||||||
|
export const PrimaryButton: FunctionComponent<PrimaryButtonProps> = ({
|
||||||
|
children,
|
||||||
|
isLoading,
|
||||||
|
...props
|
||||||
|
}) => {
|
||||||
return (
|
return (
|
||||||
<StyledPrimaryButton {...props}>
|
<StyledPrimaryButton {...props}>
|
||||||
|
{isLoading ? (
|
||||||
|
<SpinnerWrapper>
|
||||||
|
<Spinner />
|
||||||
|
<Spinner />
|
||||||
|
<Spinner />
|
||||||
|
<Spinner />
|
||||||
|
</SpinnerWrapper>
|
||||||
|
) : (
|
||||||
<span>{children}</span>
|
<span>{children}</span>
|
||||||
|
)}
|
||||||
</StyledPrimaryButton>
|
</StyledPrimaryButton>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const StyledPrimaryButton = styled.button`
|
const StyledPrimaryButton = styled.button`
|
||||||
|
display: flex;
|
||||||
|
align-items center;
|
||||||
|
justify-content: center;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
|
||||||
@ -54,3 +72,39 @@ const StyledPrimaryButton = styled.button`
|
|||||||
color: ${color.orange["50"]};
|
color: ${color.orange["50"]};
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
const SpinnerWrapper = styled.div`
|
||||||
|
display: flex;
|
||||||
|
position: relative;
|
||||||
|
|
||||||
|
width: 20px;
|
||||||
|
height: 20px;
|
||||||
|
`;
|
||||||
|
|
||||||
|
const spinAnimation = keyframes`
|
||||||
|
from {
|
||||||
|
transform: rotate(0deg);
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
transform: rotate(360deg);
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
const Spinner = styled.div<{ animationDelay?: string }>`
|
||||||
|
display: block;
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
|
||||||
|
animation: ${spinAnimation} 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
|
||||||
|
${({ animationDelay }) =>
|
||||||
|
animationDelay ? `animation-delay: ${animationDelay};` : ""}
|
||||||
|
|
||||||
|
border-radius: 100%;
|
||||||
|
border-style: solid;
|
||||||
|
border-width: 3px;
|
||||||
|
border-color: white transparent transparent transparent;
|
||||||
|
`;
|
||||||
|
@ -62,7 +62,8 @@ export default function VerificationPage() {
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [twitterAuthInfo, setTwitterAuthInfo] = useState<TwitterProfileType>();
|
const [twitterAuthInfo, setTwitterAuthInfo] = useState<TwitterProfileType>();
|
||||||
|
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
const [isLoadingInit, setIsLoadingInit] = useState(true);
|
||||||
|
const [isLoadingRegistration, setIsLoadingRegistration] = useState(false);
|
||||||
|
|
||||||
const [wallet, setWallet] = useState<KeplrWallet>();
|
const [wallet, setWallet] = useState<KeplrWallet>();
|
||||||
const [walletKey, setWalletKey] = useState<{
|
const [walletKey, setWalletKey] = useState<{
|
||||||
@ -173,7 +174,7 @@ export default function VerificationPage() {
|
|||||||
|
|
||||||
console.error(error);
|
console.error(error);
|
||||||
} finally {
|
} finally {
|
||||||
setIsLoading(false);
|
setIsLoadingInit(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -267,6 +268,7 @@ export default function VerificationPage() {
|
|||||||
amplitude.track("click register button");
|
amplitude.track("click register button");
|
||||||
|
|
||||||
console.log(isOwner);
|
console.log(isOwner);
|
||||||
|
|
||||||
if (isOwner) {
|
if (isOwner) {
|
||||||
handleRegistration();
|
handleRegistration();
|
||||||
} else {
|
} else {
|
||||||
@ -276,6 +278,8 @@ export default function VerificationPage() {
|
|||||||
|
|
||||||
const handleRegistration = async () => {
|
const handleRegistration = async () => {
|
||||||
try {
|
try {
|
||||||
|
setIsLoadingRegistration(true);
|
||||||
|
|
||||||
const { state, code } = checkTwitterAuthQueryParameter(
|
const { state, code } = checkTwitterAuthQueryParameter(
|
||||||
window.location.search,
|
window.location.search,
|
||||||
);
|
);
|
||||||
@ -358,6 +362,8 @@ export default function VerificationPage() {
|
|||||||
if (Axios.isAxiosError(error)) {
|
if (Axios.isAxiosError(error)) {
|
||||||
console.error((error?.response?.data as QueryError).message);
|
console.error((error?.response?.data as QueryError).message);
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
setIsLoadingRegistration(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -372,7 +378,7 @@ export default function VerificationPage() {
|
|||||||
<Logo />
|
<Logo />
|
||||||
|
|
||||||
<MainContainer>
|
<MainContainer>
|
||||||
{isLoading ? (
|
{isLoadingInit ? (
|
||||||
<SkeletonChainList />
|
<SkeletonChainList />
|
||||||
) : (
|
) : (
|
||||||
<ContentContainer>
|
<ContentContainer>
|
||||||
@ -426,6 +432,7 @@ export default function VerificationPage() {
|
|||||||
<PrimaryButton
|
<PrimaryButton
|
||||||
disabled={isRegisterButtonDisable}
|
disabled={isRegisterButtonDisable}
|
||||||
onClick={onClickRegistration}
|
onClick={onClickRegistration}
|
||||||
|
isLoading={isLoadingRegistration}
|
||||||
>
|
>
|
||||||
Register
|
Register
|
||||||
</PrimaryButton>
|
</PrimaryButton>
|
||||||
|
Loading…
Reference in New Issue
Block a user