diff --git a/src/features/AdminPage/Analytics/Analytics.component.tsx b/src/features/AdminPage/Analytics/Analytics.component.tsx index 882ca82d2..7518a07bd 100644 --- a/src/features/AdminPage/Analytics/Analytics.component.tsx +++ b/src/features/AdminPage/Analytics/Analytics.component.tsx @@ -12,7 +12,7 @@ import { useRouteUrl } from '@/app/common/hooks/stateful/useRouter.hook'; import base64ToUrl from '@/app/common/utils/base64ToUrl.utility'; import PageBar from '@/features/AdminPage/PageBar/PageBar.component'; import StatisticRecord from '@/models/analytics/analytics/statisticrecord.model'; -import Image from '@/models/media/image.model'; +import Image, { ImageAssigment } from '@/models/media/image.model'; import Streetcode from '@/models/streetcode/streetcode-types.model'; interface TableData { @@ -79,7 +79,7 @@ const Analytics = () => { const setImages = async (streetcodeId: number) => { await ImagesApi.getByStreetcodeId(streetcodeId ?? 1).then((imgs) => { - setImage(imgs.at(0)); + setImage(imgs.find((image) => image.imageDetails?.alt === ImageAssigment.blackandwhite.toString())); }).catch((e) => { console.log(e); }); diff --git a/src/features/AdminPage/NewStreetcode/MainBlock/FileInputsPart.component.tsx b/src/features/AdminPage/NewStreetcode/MainBlock/FileInputsPart.component.tsx index a92232ae1..6e657e999 100644 --- a/src/features/AdminPage/NewStreetcode/MainBlock/FileInputsPart.component.tsx +++ b/src/features/AdminPage/NewStreetcode/MainBlock/FileInputsPart.component.tsx @@ -7,7 +7,7 @@ import { InboxOutlined } from '@ant-design/icons'; import CreateUpdateMediaStore from '@app/stores/create-update-media-store'; import useMobx from '@app/stores/root-store'; import { ModelState } from '@models/enums/model-state'; -import Image, { ImageUpdate } from '@models/media/image.model'; +import Image, { ImageAssigment, ImageUpdate } from '@models/media/image.model'; import { FormInstance, Modal, UploadFile } from 'antd'; import FormItem from 'antd/es/form/FormItem'; @@ -144,18 +144,25 @@ const FileInputsPart = ({ form, onChange }: FileInputsPartProps) => { const fetchData = async () => { try { await ImagesApi.getByStreetcodeId(parseId).then((result) => { - setAnimation([convertFileToUploadFile(result[0])]); - setBlackAndWhite([convertFileToUploadFile(result[1])]); - setRelatedFigure(result[2] ? [convertFileToUploadFile(result[2])] : []); - form.setFieldsValue({ - animations: [convertFileToUploadFile(result[0])], - pictureBlackWhite: [convertFileToUploadFile(result[1])], - pictureRelations: result[2] ? [convertFileToUploadFile(result[2])] : [], - }); + result.forEach((image) => { + if (image.imageDetails?.alt === ImageAssigment.animation.toString()) { + setAnimation([convertFileToUploadFile(image)]); + form.setFieldsValue({ animations: [convertFileToUploadFile(image)] }); + createUpdateMediaStore.animationId = image.id; + } - createUpdateMediaStore.animationId = result[0].id; - createUpdateMediaStore.blackAndWhiteId = result[1].id; - createUpdateMediaStore.relatedFigureId = result[2]?.id; + if (image.imageDetails?.alt === ImageAssigment.blackandwhite.toString()) { + setBlackAndWhite([convertFileToUploadFile(image)]); + form.setFieldsValue({ pictureBlackWhite: [convertFileToUploadFile(image)] }); + createUpdateMediaStore.blackAndWhiteId = image.id; + } + + if (image.imageDetails?.alt === ImageAssigment.relatedfigure.toString()) { + setRelatedFigure([convertFileToUploadFile(image)]); + form.setFieldsValue({ pictureRelations: [convertFileToUploadFile(image)] }); + createUpdateMediaStore.relatedFigureId = image.id; + } + }); createUpdateMediaStore.imagesUpdate = result.map((img) => ({ ...img, @@ -193,10 +200,6 @@ const FileInputsPart = ({ form, onChange }: FileInputsPartProps) => { name="animations" label="Анімація" rules={[ - { - required: true, - message: 'Завантажте анімацію', - }, { validator: (_, file) => { if (file) { @@ -211,7 +214,7 @@ const FileInputsPart = ({ form, onChange }: FileInputsPartProps) => { } return Promise.reject(Error('Тільки файли з розширенням .gif та .webp дозволені!')); } - return Promise.reject(); + return Promise.resolve(); }, }, ]} diff --git a/src/features/StreetcodePage/MainBlock/StreetcodeCard/StreetcodeCard.component.tsx b/src/features/StreetcodePage/MainBlock/StreetcodeCard/StreetcodeCard.component.tsx index e4884ca49..919367199 100644 --- a/src/features/StreetcodePage/MainBlock/StreetcodeCard/StreetcodeCard.component.tsx +++ b/src/features/StreetcodePage/MainBlock/StreetcodeCard/StreetcodeCard.component.tsx @@ -16,7 +16,7 @@ import ImagesApi from '@/app/api/media/images.api'; import TransactionLinksApi from '@/app/api/transactions/transactLinks.api'; import base64ToUrl from '@/app/common/utils/base64ToUrl.utility'; import { audioClickEvent, personLiveEvent } from '@/app/common/utils/googleAnalytics.unility'; -import Image from '@/models/media/image.model'; +import Image, { ImageAssigment } from '@/models/media/image.model'; const fullMonthNumericYearDateFmtr = new Intl.DateTimeFormat('uk-UA', { day: 'numeric', @@ -87,7 +87,8 @@ const StreetcodeCard = ({ streetcode, setActiveTagId, setActiveBlock }: Props) = swipeOnClick infinite > - {images.slice(0, 2).map((im) => ( + {images.filter((image) => (image.imageDetails?.alt === ImageAssigment.animation.toString() + || image.imageDetails?.alt === ImageAssigment.blackandwhite.toString())).map((im) => (