Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import { Button, DEFAULT_DATE_FORMAT, FCWithClassName, FileModel } from '@tmk/ui-kit'
import { ChangeLogStatusEnum, NewValue, ChangeLogValues } from '../../lib'
import { TFunction } from '@/shared/@types'
import { DocumentFile, ChangeLogStatus, ChangeLogCustomProperty } from '@/entities/change-log'
import dayjs from 'dayjs'
import Link from 'next/link'
import { getDateFormat } from '@/shared/helpers'
import { AcceptanceTransport } from '@/entities/accounting-object'
import EyeIcon from '@/shared/assets/icons/common/open-eye.svg'
import { formatPrice } from '@/features/measure'
import { PipeStatus, PipeStatusEnum } from '@/entities/pipe'
import { MassEditPropertyValue } from '@/entities/property'
import { getFileFromFiles } from '@/entities/files'
import { Document, getRecordFiles } from '@/entities/documents'
export interface ChangeLogNewValueProps {
value: NewValue | ChangeLogValues
t: TFunction
isShowDocumentBtn?: boolean
documentBtnHandler?: () => void
repairHandler?: () => void
isNeedDetailBtn?: boolean
files?: FileModel[]
isFilesLoading?: boolean
documents?: Document[]
isLoadingDocuments?: boolean
}
export const ChangeLogValue: FCWithClassName<ChangeLogNewValueProps> = ({
className,
value,
t,
isShowDocumentBtn,
documentBtnHandler,
repairHandler,
isNeedDetailBtn,
files,
isFilesLoading,
documents,
isLoadingDocuments,
}) => {
const getTranslateFields = (value: string, key: string) => {
const fieldsToTranslate = [
'affiliation',
'pipeLabelType',
'accountingType',
'muftType',
'muftFask',
'greenWellOption',
'execution',
'shipmentType',
'casing',
]
const notationFields = ['lengthScaleNotation', 'weightScaleNotation', 'makeUpLengthLossNotation']
if (!value) return '-'
if (key === 'lockPrice') return t(`accounting-object:per_${value}`)
if (notationFields.includes(key)) return t(`common:${value}`)
if (key === 'affiliation') return t(`accounting-object:affiliation_${value}`)
if (fieldsToTranslate.includes(key)) return t(`accounting-object:${value}`)
return value
}
const getTranslateDateFields = (key: string) => {
if ('inspectionDate' in value && key === 'date') return t('accounting-object:inspectionDate')
if ('inspectionDate' in value && key === 'inspectionDate') return t('accounting-object:next_inspection_date')
if (key == 'date') return t('accounting-object:dateOperation')
return t(`accounting-object:${key}`)
}
return (
<div className='flex flex-col h-full gap-2 py-3 my-3 align-baseline'>
{value &&
Object.entries(value).map(([key, value]) => {
const isCustomProperty = key.substring(0, 3) === 'cp_'
if (key === 'id' || key === '@id') return
if (value?.date && !isCustomProperty) {
if (key)
return (
<div className='flex items-center gap-2'>
{getTranslateDateFields(key)}:
<div key={key} className='text-black text-min-semibold'>{`${dayjs(value.date).format(
getDateFormat(key)
)}`}</div>
</div>
)
}
if (key === 'priceItem' || key === 'priceMeter' || key === 'priceTon') {
return (
<div key={key}>
{t(`accounting-object:${key}`)}:{' '}
<span className='text-black text-min-semibold'>{formatPrice(value)}</span>
</div>
)
}
if (isCustomProperty) {
const propertyName = isCustomProperty ? key.substring(3) : ''
const propertyValue = value?.date ? dayjs(value?.date).format(DEFAULT_DATE_FORMAT) : value
return <ChangeLogCustomProperty key={key} propertyName={propertyName} propertyValue={propertyValue} />
}
switch (key) {
case 'state':
return (
<div className='flex items-center gap-2' key={key}>
{t(`accounting-object:${key}`)}:
<ChangeLogStatus status={value as ChangeLogStatusEnum} className='text-black text-min-semibold' />
</div>
)
case 'transport':
return (
<div className='flex items-center gap-2'>
{t('accounting-object:transport')}:
{Array.isArray(value) &&
(value as AcceptanceTransport[]).map(transport => (
<div key={transport.id} className='flex items-center'>
<span className='text-black text-min-semibold'>{t(`common:${transport.type}`)}</span>
{!!transport.vans?.length && (
<span className='text-black text-min-semibold'>
{' '}
- {t('accounting-object:Train')} {transport.vans.map(item => item.number).join(',')}
</span>
)}
;
</div>
))}
</div>
)
case 'repairTypes':
return (
<ul key={key} className='flex flex-col gap-2 ml-4'>
{Array.isArray(value) &&
value?.map(inspectionType => (
<li key={inspectionType} className='list-disc text-min'>
{inspectionType?.v
? getTranslateFields(inspectionType.v, key)
: getTranslateFields(inspectionType?.toString(), key)}
</li>
))}
</ul>
)
case 'status':
return (
<div className='flex items-center gap-2' key={key}>
{t(`accounting-object:${key}`)}:
<PipeStatus status={value as PipeStatusEnum} />
</div>
)
case 'inspectionTypes':
return (
<ul key={key} className='flex flex-col gap-2 ml-4'>
{Array.isArray(value) &&
value?.map(inspectionType => (
<li key={inspectionType} className='list-disc text-min'>
{inspectionType?.v
? getTranslateFields(inspectionType.v, key)
: getTranslateFields(inspectionType?.toString(), key)}
</li>
))}
</ul>
)
case 'customProperties':
return (
<div className='flex flex-wrap gap-1 ' key={key}>
{Array.isArray(value) &&
value?.map((customProperty: MassEditPropertyValue) => (
<ChangeLogCustomProperty key={customProperty.property} massValue={customProperty} />
))}
</div>
)
case 'documents':
return (
<div key={key} className='flex flex-wrap gap-2 '>
{getRecordFiles<Document>(documents, value)?.map(document => (
<DocumentFile
key={document.id}
id={document.id}
isNeedDocument={false}
fileFromParent={document.file}
isFileFromParent
isLoadingFileFromParent={isLoadingDocuments}
/>
))}
</div>
)
case 'file':
return (
<DocumentFile
id={value}
isNeedDocument={false}
isFileFromParent
fileFromParent={getFileFromFiles(files, value?.file)}
isLoadingFileFromParent={isFilesLoading}
/>
)
case 'mediaFiles':
return (
<div key={key} className='flex flex-wrap gap-2 '>
{getRecordFiles<FileModel>(files, value)?.map(mediaFile => (
<DocumentFile
key={mediaFile.id}
id={mediaFile.id}
isNeedDocument={false}
fileFromParent={getFileFromFiles(files, mediaFile.id)}
isFileFromParent
isLoadingFileFromParent={isLoadingDocuments}
/>
))}
</div>
)
case 'totalShortage':
return (
<div key={key}>
{t(`accounting-object:${key}`)}:{' '}
<span className='text-black text-min-semibold'>
{value} {t('common:pcs')}
</span>
</div>
)
case 'totalSurplus':
return (
<div key={key}>
{t(`accounting-object:${key}`)}:{' '}
<span className='text-black text-min-semibold'>
{value} {t('common:pcs')}
</span>
</div>
)
case 'links':
return (
<div className='flex flex-wrap gap-1' key={key}>
{Array.isArray(value) && value.length
? value?.map(link => (
<div key={link.id} className='w-40 p-2 truncate bg-gray-tertiary rounded-base'>
<p className='text-left text-text-secondary'>{link?.name}</p>
<Link href={link.link} target='_blank'>
<span className='cursor-pointer text-blue-dark text-min-semibold'>{link?.link}</span>
</Link>
</div>
))
: ''}
</div>
)
default:
return (
<div key={key}>
{t(`accounting-object:${key}`)}:{' '}
<span className='text-black text-min-semibold'>
{value?.v ? getTranslateFields(value.v, key) : getTranslateFields(value?.toString(), key)}
</span>
</div>
)
}
})}
{isShowDocumentBtn && (
<Button variant='text' childrenClassName='flex items-center gap-x-2.5'>
<EyeIcon className='stroke-blue-dark' />
<span onClick={documentBtnHandler} className='text-blue-dark text-main-semibold whitespace-nowrap'>
{t('accounting-object:Show_documents')}
</span>
</Button>
)}
{isNeedDetailBtn && (
<Button variant='text' childrenClassName='flex items-center gap-x-2.5' onClick={repairHandler}>
<EyeIcon className='stroke-blue-dark' />
<span className='text-blue-dark text-main-semibold whitespace-nowrap'>
{t('accounting-object:Learn_more_about_the_changes')}
</span>
</Button>
)}
</div>
)
}
|