1
0
mirror of https://github.com/Infisical/infisical.git synced 2025-03-31 22:09:57 +00:00

refactor: convert usequery hook to normal fetch fn (no need for caching)

This commit is contained in:
lemmyMwaura
2024-08-07 08:27:17 +03:00
parent da45e132a3
commit 406da1b5f0
2 changed files with 20 additions and 32 deletions
frontend/src
hooks/api/secretSharing
views/ViewSecretPublicPage/components

@ -68,29 +68,18 @@ export const useGetActiveSharedSecretById = ({
});
};
export const useValidateSecretPassword = ({
sharedSecretId,
hashedHex,
userPassword,
}: {
sharedSecretId: string;
hashedHex: string;
userPassword: string;
}) => {
return useQuery(
[`validateSecretPass-${sharedSecretId}`],
async () => {
const { data } = await apiRequest.post<ValidateSecretPassword>(
`/api/v1/secret-sharing/public/${sharedSecretId}/validate`,
{
hashedHex,
password: userPassword
}
);
return data;
},
export const fetchIsSecretPasswordValid = async (
sharedSecretId: string,
hashedHex: string,
password: string,
) => {
const { data } = await apiRequest.post<ValidateSecretPassword>(
`/api/v1/secret-sharing/public/${sharedSecretId}/validate`,
{
enabled: Boolean(sharedSecretId) && Boolean(userPassword),
hashedHex,
password
}
)
}
);
return data;
};

@ -4,7 +4,7 @@ import { faArrowRight, faSpinner } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { Button, IconButton, Input } from "@app/components/v2";
import { useValidateSecretPassword } from "@app/hooks/api/secretSharing";
import { fetchIsSecretPasswordValid } from "@app/hooks/api/secretSharing";
import { createNotification } from "@app/components/notifications";
type Props = {
@ -16,11 +16,6 @@ type Props = {
export const PasswordContainer = ({ secretId, hashedHex, handlePassMatch }: Props) => {
const [password, setPassword] = useState<string>('')
const [isLoading, setLoading] = useState(false)
const { refetch } = useValidateSecretPassword({
sharedSecretId: secretId,
hashedHex,
userPassword: password,
})
const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
setPassword(e.target.value)
@ -30,9 +25,13 @@ export const PasswordContainer = ({ secretId, hashedHex, handlePassMatch }: Prop
setLoading(true);
try {
const { data: freshData } = await refetch();
const data = await fetchIsSecretPasswordValid(
secretId,
hashedHex,
password,
)
if (freshData?.isValid === true) {
if (data?.isValid === true) {
handlePassMatch(true);
} else {
createNotification({