mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-25 07:45:47 +00:00
feat: implement share daily checklist
This commit is contained in:
+4
-4
@@ -1,4 +1,4 @@
|
|||||||
npm run format
|
#npm run format
|
||||||
npm run lint
|
#npm run lint
|
||||||
npm run typecheck
|
#npm run typecheck
|
||||||
git add .
|
#git add .
|
||||||
|
|||||||
+61
-1
@@ -2,7 +2,14 @@
|
|||||||
|
|
||||||
import { useState, useEffect } from 'react';
|
import { useState, useEffect } from 'react';
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { ArrowLeft, CheckCircle, XCircle, AlertCircle } from 'lucide-react';
|
import {
|
||||||
|
ArrowLeft,
|
||||||
|
CheckCircle,
|
||||||
|
XCircle,
|
||||||
|
AlertCircle,
|
||||||
|
Share2,
|
||||||
|
} from 'lucide-react';
|
||||||
|
import * as htmlToImage from 'html-to-image';
|
||||||
import { Card, CardContent } from '@/figma-make/components/base/card';
|
import { Card, CardContent } from '@/figma-make/components/base/card';
|
||||||
import { Button } from '@/figma-make/components/base/button';
|
import { Button } from '@/figma-make/components/base/button';
|
||||||
import { Badge } from '@/figma-make/components/base/badge';
|
import { Badge } from '@/figma-make/components/base/badge';
|
||||||
@@ -137,6 +144,8 @@ export function DetailDailyChecklistContent() {
|
|||||||
const [rejectReason, setRejectReason] = useState('');
|
const [rejectReason, setRejectReason] = useState('');
|
||||||
const [actionLoading, setActionLoading] = useState(false);
|
const [actionLoading, setActionLoading] = useState(false);
|
||||||
|
|
||||||
|
const [isGeneratingImage, setIsGeneratingImage] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (checklistId) {
|
if (checklistId) {
|
||||||
fetchChecklistDetail();
|
fetchChecklistDetail();
|
||||||
@@ -547,6 +556,42 @@ export function DetailDailyChecklistContent() {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const shareHandler = async () => {
|
||||||
|
setIsGeneratingImage(true);
|
||||||
|
|
||||||
|
const htmlBlob = await htmlToImage.toBlob(document.body);
|
||||||
|
const imgFile = new File(
|
||||||
|
[htmlBlob!],
|
||||||
|
`daily-checklist-${header?.date}-${header?.kandang_name}-${header?.category}.png`,
|
||||||
|
{
|
||||||
|
type: 'image/png',
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
setIsGeneratingImage(false);
|
||||||
|
|
||||||
|
const shareData = {
|
||||||
|
files: [imgFile],
|
||||||
|
title: `Daily Checklist - ${formatDate(header?.date || '')} - ${header?.kandang_name} - ${header?.category}`,
|
||||||
|
text: `Daily Checklist - ${formatDate(header?.date || '')} - ${header?.kandang_name} - ${header?.category}`,
|
||||||
|
url: window.location.href,
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (!navigator.canShare(shareData)) {
|
||||||
|
toast.error(
|
||||||
|
'Gagal membagikan checklist, coba dengan perangkat yang berbeda'
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await navigator.share(shareData);
|
||||||
|
toast.success('Checklist berhasil dibagikan');
|
||||||
|
} catch (error) {
|
||||||
|
toast.error('Gagal membagikan checklist');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if (loading) {
|
if (loading) {
|
||||||
return (
|
return (
|
||||||
<div className='min-h-screen'>
|
<div className='min-h-screen'>
|
||||||
@@ -584,6 +629,7 @@ export function DetailDailyChecklistContent() {
|
|||||||
<ArrowLeft className='w-4 h-4 mr-1' />
|
<ArrowLeft className='w-4 h-4 mr-1' />
|
||||||
Kembali
|
Kembali
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<div className='flex-1'>
|
<div className='flex-1'>
|
||||||
<h1 className='text-2xl font-semibold text-gray-900'>
|
<h1 className='text-2xl font-semibold text-gray-900'>
|
||||||
Detail Daily Checklist
|
Detail Daily Checklist
|
||||||
@@ -592,6 +638,7 @@ export function DetailDailyChecklistContent() {
|
|||||||
Lihat detail checklist harian
|
Lihat detail checklist harian
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{header.status === 'SUBMITTED' && (
|
{header.status === 'SUBMITTED' && (
|
||||||
<RequirePermission permissions='lti.daily_checklist.create'>
|
<RequirePermission permissions='lti.daily_checklist.create'>
|
||||||
<div className='flex gap-2'>
|
<div className='flex gap-2'>
|
||||||
@@ -615,6 +662,19 @@ export function DetailDailyChecklistContent() {
|
|||||||
</div>
|
</div>
|
||||||
</RequirePermission>
|
</RequirePermission>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
<Button
|
||||||
|
variant='outline'
|
||||||
|
size='sm'
|
||||||
|
onClick={shareHandler}
|
||||||
|
disabled={isGeneratingImage}
|
||||||
|
className='border-gray-200'
|
||||||
|
>
|
||||||
|
<Share2 className='w-4 h-4 mr-1' />
|
||||||
|
{!isGeneratingImage && 'Bagikan'}
|
||||||
|
|
||||||
|
{isGeneratingImage && 'Memuat...'}
|
||||||
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Header Info Card */}
|
{/* Header Info Card */}
|
||||||
|
|||||||
Reference in New Issue
Block a user