diff options
Diffstat (limited to 'lib/vendor-document-list')
| -rw-r--r-- | lib/vendor-document-list/ship/send-to-shi-button.tsx | 70 |
1 files changed, 35 insertions, 35 deletions
diff --git a/lib/vendor-document-list/ship/send-to-shi-button.tsx b/lib/vendor-document-list/ship/send-to-shi-button.tsx index 532aabf5..52874702 100644 --- a/lib/vendor-document-list/ship/send-to-shi-button.tsx +++ b/lib/vendor-document-list/ship/send-to-shi-button.tsx @@ -36,8 +36,8 @@ interface SendToSHIButtonProps { projectType: "ship" | "plant" } -export function SendToSHIButton({ - documents = [], +export function SendToSHIButton({ + documents = [], onSyncComplete, projectType }: SendToSHIButtonProps) { @@ -51,13 +51,13 @@ export function SendToSHIButton({ const { t } = useTranslation(lng, "engineering") const targetSystem = projectType === 'ship' ? "DOLCE" : "SWP" - + // 문서에서 유효한 계약 ID 목록 추출 (projectId 사용) const documentsContractIds = React.useMemo(() => { const validIds = documents .map(doc => (doc as any).projectId) .filter((id): id is number => typeof id === 'number' && id > 0) - + const uniqueIds = [...new Set(validIds)] return uniqueIds.sort() }, [documents]) @@ -66,7 +66,7 @@ export function SendToSHIButton({ // ✅ 클라이언트 전용 Hook 사용 (서버 사이드 렌더링 호환) const { contractStatuses, totalStats, refetchAll } = useClientSyncStatus( - documentsContractIds, + documentsContractIds, targetSystem ) @@ -79,14 +79,14 @@ export function SendToSHIButton({ toast.info(t('shiSync.messages.noContractsToSync')) return } - + setSyncProgress(0) let successfulSyncs = 0 let failedSyncs = 0 let totalSuccessCount = 0 let totalFailureCount = 0 const errors: string[] = [] - + try { // 동기화 가능한 계약들만 필터링 const contractsToSync = contractStatuses.filter(({ syncStatus, error }) => { @@ -112,14 +112,14 @@ export function SendToSHIButton({ for (let i = 0; i < contractsToSync.length; i++) { const { projectId } = contractsToSync[i] setCurrentSyncingContract(projectId) - + try { console.log(`Syncing contract ${projectId}...`) - const result = await triggerSync({ - projectId, - targetSystem + const result = await triggerSync({ + projectId, + targetSystem }) - + if (result?.success) { successfulSyncs++ totalSuccessCount += result.successCount || 0 @@ -143,12 +143,12 @@ export function SendToSHIButton({ } setCurrentSyncingContract(null) - + // 결과 처리 및 토스트 표시 setTimeout(() => { setSyncProgress(0) setIsDialogOpen(false) - + if (failedSyncs === 0) { toast.success( t('shiSync.messages.allSyncCompleted', { successCount: totalSuccessCount }), @@ -161,12 +161,12 @@ export function SendToSHIButton({ ) } else if (successfulSyncs > 0) { toast.warning( - t('shiSync.messages.partialSyncCompleted', { - successfulCount: successfulSyncs, - failedCount: failedSyncs + t('shiSync.messages.partialSyncCompleted', { + successfulCount: successfulSyncs, + failedCount: failedSyncs }), { - description: errors.slice(0, 3).join(', ') + + description: errors.slice(0, 3).join(', ') + (errors.length > 3 ? t('shiSync.messages.andMore') : '') } ) @@ -178,16 +178,16 @@ export function SendToSHIButton({ } ) } - + // 모든 contract 상태 갱신 refetchAll() onSyncComplete?.() }, 500) - + } catch (error) { setSyncProgress(0) setCurrentSyncingContract(null) - + const errorMessage = syncUtils.formatError(error as Error) toast.error(t('shiSync.messages.syncFailed'), { description: errorMessage @@ -259,8 +259,8 @@ export function SendToSHIButton({ )} <span className="hidden sm:inline">{t('shiSync.buttons.sendToSHI')}</span> {totalStats.totalPending > 0 && ( - <Badge - variant="destructive" + <Badge + variant="destructive" className="h-5 w-5 p-0 text-xs flex items-center justify-center ml-1" > {totalStats.totalPending} @@ -269,7 +269,7 @@ export function SendToSHIButton({ </Button> </div> </PopoverTrigger> - + <PopoverContent className="w-96" align="end"> <div className="space-y-4"> <div className="space-y-2"> @@ -289,16 +289,16 @@ export function SendToSHIButton({ )} </Button> </div> - + <div className="flex items-center justify-between"> <span className="text-sm text-muted-foreground">{t('shiSync.labels.overallStatus')}</span> {getSyncStatusBadge()} </div> - + <div className="text-xs text-muted-foreground"> - {t('shiSync.descriptions.targetInfo', { - contractCount: documentsContractIds.length, - targetSystem + {t('shiSync.descriptions.targetInfo', { + contractCount: documentsContractIds.length, + targetSystem })} </div> </div> @@ -311,8 +311,8 @@ export function SendToSHIButton({ {t('shiSync.descriptions.statusCheckError')} {process.env.NODE_ENV === 'development' && ( <div className="text-xs mt-1 font-mono"> - Debug: {t('shiSync.descriptions.contractsWithError', { - count: contractStatuses.filter(({ error }) => error).length + Debug: {t('shiSync.descriptions.contractsWithError', { + count: contractStatuses.filter(({ error }) => error).length })} </div> )} @@ -324,7 +324,7 @@ export function SendToSHIButton({ {!totalStats.hasError && documentsContractIds.length > 0 && ( <div className="space-y-3"> <Separator /> - + <div className="grid grid-cols-3 gap-4 text-sm"> <div className="text-center"> <div className="text-muted-foreground">{t('shiSync.labels.pending')}</div> @@ -409,7 +409,7 @@ export function SendToSHIButton({ </> )} </Button> - + <Button variant="outline" size="sm" @@ -451,12 +451,12 @@ export function SendToSHIButton({ <span>{t('shiSync.labels.syncTarget')}</span> <span className="font-medium">{t('shiSync.labels.itemCount', { count: totalStats.totalPending })}</span> </div> - + <div className="flex items-center justify-between text-sm"> <span>{t('shiSync.labels.targetContracts')}</span> <span className="font-medium">{t('shiSync.labels.contractCount', { count: documentsContractIds.length })}</span> </div> - + <div className="text-xs text-muted-foreground"> {t('shiSync.descriptions.includesChanges')} </div> |
