feat: added option for link expiry
Signed-off-by: Varun Raj <varun@skcript.com>
This commit is contained in:
1 parent
fdef491586
commit
d5c6f0ac29
8 files changed
+214
-146
No files matched your search
@@ -5,8 +5,9 @@ import { ShareLinkFilters } from '@/types/shareLink';
|
||||
import { generateShareLink } from '@/handlers/api/shareLink.handler';
|
||||
import { Input } from '../ui/input';
|
||||
import { Label } from '@radix-ui/react-label';
|
||||
import { Checkbox } from '../ui/checkbox';
|
||||
|
||||
import { Switch } from '../ui/switch';
|
||||
import { Select, SelectValue, SelectContent, SelectItem, SelectTrigger } from '../ui/select';
|
||||
|
||||
|
||||
interface ShareAssetsTriggerProps {
|
||||
@@ -19,10 +20,18 @@ export default function ShareAssetsTrigger({ filters, buttonProps }: ShareAssets
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [errorMessage, setErrorMessage] = useState<string | null>(null);
|
||||
const [copied, setCopied] = useState(false);
|
||||
const [config, setConfig] = useState<Partial<ShareLinkFilters>>({});
|
||||
const [config, setConfig] = useState<Partial<ShareLinkFilters>>({
|
||||
expiresIn: "never"
|
||||
});
|
||||
|
||||
const handleReset = () => {
|
||||
setConfig({ expiresIn: "never" });
|
||||
setGeneratedLink(null);
|
||||
}
|
||||
|
||||
const handleGenerate = async () => {
|
||||
setLoading(true);
|
||||
setErrorMessage(null);
|
||||
return generateShareLink({ ...filters, ...config }).then(({ link }) => {
|
||||
setGeneratedLink(link);
|
||||
}).catch((err) => {
|
||||
@@ -63,20 +72,41 @@ export default function ShareAssetsTrigger({ filters, buttonProps }: ShareAssets
|
||||
This is a stateless link, it will not work if you leave the page. Which means it cannot be expired.
|
||||
</p>
|
||||
<div className="flex gap-2">
|
||||
<Button className="w-full" onClick={handleCopy}>{copied ? 'Copied' : 'Copy'}</Button>
|
||||
<Button className="w-full" variant="outline" onClick={handleGenerate}>Generate New Link</Button>
|
||||
<Button className="w-full" onClick={handleCopy}>{copied ? 'Copied' : 'Copy'}</Button>
|
||||
<Button className="w-full" variant="outline" onClick={handleReset}>Generate New Link</Button>
|
||||
</div>
|
||||
</div> : (
|
||||
<div className="flex flex-col gap-4">
|
||||
<div className="flex items-center justify-between gap-1">
|
||||
<div className="flex flex-col gap-1">
|
||||
<Label className="text-sm m-0">Show People</Label>
|
||||
<p className="text-xs text-muted-foreground m-0">
|
||||
Show the list of people in the shared photos
|
||||
</p>
|
||||
<Label className="text-sm m-0">Show People</Label>
|
||||
<p className="text-xs text-muted-foreground m-0">
|
||||
Show the list of people in the shared photos
|
||||
</p>
|
||||
</div>
|
||||
<Switch checked={config.p} onCheckedChange={(checked) => setConfig({ ...config, p: !!checked })} />
|
||||
</div>
|
||||
<div className="flex items-center justify-between gap-1">
|
||||
<div className="flex flex-col gap-1">
|
||||
<Label className="text-sm m-0">Link Expires In</Label>
|
||||
<p className="text-xs text-muted-foreground m-0">
|
||||
Should the link expire after the selected time
|
||||
</p>
|
||||
</div>
|
||||
<Select onValueChange={(value) => setConfig({ ...config, expiresIn: value })}>
|
||||
<SelectTrigger className='w-fit'>
|
||||
<SelectValue placeholder="Select duration" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="1h">1 Hour</SelectItem>
|
||||
<SelectItem value="1d">1 Day (24 Hours)</SelectItem>
|
||||
<SelectItem value="7d">7 Days</SelectItem>
|
||||
<SelectItem value="30d">30 Days</SelectItem>
|
||||
<SelectItem value="90d">90 Days</SelectItem>
|
||||
<SelectItem value="never">Never Expires</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<Button onClick={handleGenerate} disabled={loading}>Generate Share Link</Button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
Reference in new issue
Block a user