2025-01-07 02:29:29 +08:00
|
|
|
'use client';
|
|
|
|
|
|
|
|
import { BusterLogo } from '@/assets/svg/BusterLogo';
|
|
|
|
import React, { useRef } from 'react';
|
2025-03-05 02:56:15 +08:00
|
|
|
import type { ShareAssetType } from '@/api/asset_interfaces';
|
2025-01-07 02:29:29 +08:00
|
|
|
import { useBusterAssetsContextSelector } from '@/context/Assets/BusterAssetsProvider';
|
2025-03-08 07:02:56 +08:00
|
|
|
import { useMemoizedFn } from '@/hooks';
|
2025-03-05 02:56:15 +08:00
|
|
|
import { Title, Text } from '@/components/ui/typography';
|
|
|
|
import { Button } from '@/components/ui/buttons';
|
|
|
|
import { Input } from '@/components/ui/inputs';
|
2025-01-07 02:29:29 +08:00
|
|
|
|
|
|
|
export const AppPasswordAccess: React.FC<{
|
2025-03-19 03:04:21 +08:00
|
|
|
assetId: string;
|
2025-02-01 02:04:49 +08:00
|
|
|
type: ShareAssetType;
|
2025-01-07 02:29:29 +08:00
|
|
|
children: React.ReactNode;
|
2025-04-11 06:05:25 +08:00
|
|
|
}> = React.memo(({ children, assetId, type }) => {
|
2025-01-07 02:29:29 +08:00
|
|
|
const getAssetPassword = useBusterAssetsContextSelector((state) => state.getAssetPassword);
|
2025-03-19 03:04:21 +08:00
|
|
|
const { password, error } = getAssetPassword(assetId);
|
2025-01-07 02:29:29 +08:00
|
|
|
|
|
|
|
if (password && !error) {
|
|
|
|
return <>{children}</>;
|
|
|
|
}
|
|
|
|
|
2025-04-11 06:05:25 +08:00
|
|
|
return (
|
|
|
|
<AppPasswordInputComponent password={password} error={error} assetId={assetId} type={type} />
|
|
|
|
);
|
2025-01-07 02:29:29 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
AppPasswordAccess.displayName = 'AppPasswordAccess';
|
|
|
|
|
|
|
|
const AppPasswordInputComponent: React.FC<{
|
|
|
|
password: string | undefined;
|
|
|
|
error: string | null;
|
2025-03-19 03:04:21 +08:00
|
|
|
assetId: string;
|
2025-04-11 06:05:25 +08:00
|
|
|
type: ShareAssetType;
|
|
|
|
}> = ({ password, error, assetId, type }) => {
|
|
|
|
const onSetAssetPassword = useBusterAssetsContextSelector((state) => state.onSetAssetPassword);
|
2025-03-05 02:56:15 +08:00
|
|
|
const inputRef = useRef<HTMLInputElement>(null);
|
2025-01-07 02:29:29 +08:00
|
|
|
|
|
|
|
const onEnterPassword = useMemoizedFn((v: string) => {
|
2025-04-11 06:05:25 +08:00
|
|
|
onSetAssetPassword(assetId, v, type);
|
2025-01-07 02:29:29 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
const onPressEnter = useMemoizedFn((v: React.KeyboardEvent<HTMLInputElement>) => {
|
|
|
|
onEnterPassword(v.currentTarget.value);
|
|
|
|
});
|
|
|
|
|
|
|
|
const onEnterButtonPress = useMemoizedFn(() => {
|
2025-03-05 02:56:15 +08:00
|
|
|
const value = inputRef.current?.value;
|
2025-01-07 02:29:29 +08:00
|
|
|
if (!value) return;
|
|
|
|
onEnterPassword(value || '');
|
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
2025-03-05 02:56:15 +08:00
|
|
|
<div
|
|
|
|
className="flex h-full min-h-[100vh] w-full justify-center"
|
|
|
|
style={{
|
|
|
|
marginTop: '25vh'
|
|
|
|
}}>
|
2025-03-12 07:01:39 +08:00
|
|
|
<div className="flex max-w-[440px] flex-col items-center space-y-6">
|
2025-03-05 02:56:15 +08:00
|
|
|
<BusterLogo className="h-16 w-16" />
|
2025-01-07 02:29:29 +08:00
|
|
|
|
2025-03-05 02:56:15 +08:00
|
|
|
<div className="text-center">
|
|
|
|
<Title
|
|
|
|
as="h2"
|
|
|
|
className="text-center">{`To access this page, enter the password below`}</Title>
|
|
|
|
</div>
|
2025-01-07 02:29:29 +08:00
|
|
|
|
2025-03-05 02:56:15 +08:00
|
|
|
<div className="flex w-full flex-col space-y-2 space-x-0">
|
|
|
|
<div className="flex flex-col space-y-1">
|
|
|
|
<Input
|
|
|
|
ref={inputRef}
|
|
|
|
defaultValue={password}
|
|
|
|
onPressEnter={onPressEnter}
|
|
|
|
className="w-full"
|
|
|
|
placeholder="Enter password"
|
|
|
|
type="password"
|
2025-04-11 06:05:25 +08:00
|
|
|
autoFocus
|
2025-03-05 02:56:15 +08:00
|
|
|
/>
|
2025-04-11 06:05:25 +08:00
|
|
|
{/* {error ? (
|
2025-03-05 02:56:15 +08:00
|
|
|
<Text className="mb-1!" variant="danger">
|
|
|
|
{error}
|
|
|
|
</Text>
|
2025-04-11 06:05:25 +08:00
|
|
|
) : null} */}
|
2025-01-07 02:29:29 +08:00
|
|
|
</div>
|
2025-03-05 02:56:15 +08:00
|
|
|
|
|
|
|
<Button block variant="black" onClick={onEnterButtonPress}>
|
|
|
|
Submit
|
|
|
|
</Button>
|
2025-01-07 02:29:29 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
2025-03-05 02:56:15 +08:00
|
|
|
</div>
|
2025-01-07 02:29:29 +08:00
|
|
|
);
|
|
|
|
};
|