From a09ba42b932e5b38b83a31853b45cf20849fd7fd Mon Sep 17 00:00:00 2001 From: yaakymiv Date: Tue, 18 Jun 2024 20:44:48 +0300 Subject: [PATCH] fix to remove unused arts --- .../MainNewStreetcode.component.tsx | 781 ++++++++++++------ .../MainNewStreetcode.styles.scss | 5 + .../StreetcodeArtsBlock.component.tsx | 1 + 3 files changed, 513 insertions(+), 274 deletions(-) diff --git a/src/features/AdminPage/NewStreetcode/MainNewStreetcode.component.tsx b/src/features/AdminPage/NewStreetcode/MainNewStreetcode.component.tsx index edc440b9f..985c19a52 100644 --- a/src/features/AdminPage/NewStreetcode/MainNewStreetcode.component.tsx +++ b/src/features/AdminPage/NewStreetcode/MainNewStreetcode.component.tsx @@ -4,7 +4,11 @@ import './MainNewStreetcode.styles.scss'; import { useCallback, useEffect, useRef, useState } from 'react'; -import { unstable_usePrompt as usePrompt, useNavigate, useParams } from 'react-router-dom'; +import { + unstable_usePrompt as usePrompt, + useNavigate, + useParams, +} from 'react-router-dom'; import SubtitlesApi from '@app/api/additional-content/subtitles.api'; import VideosApi from '@app/api/media/videos.api'; import PartnersApi from '@app/api/partners/partners.api'; @@ -18,13 +22,16 @@ import StreetcodeArtsBlock from '@features/AdminPage/NewStreetcode/StreetcodeArt import PageBar from '@features/AdminPage/PageBar/PageBar.component'; import StreetcodeCoordinate from '@models/additional-content/coordinate.model'; import { ModelState } from '@models/enums/model-state'; -import { RelatedFigureCreateUpdate, RelatedFigureUpdate } from '@models/streetcode/related-figure.model'; +import { + RelatedFigureCreateUpdate, + RelatedFigureUpdate, +} from '@models/streetcode/related-figure.model'; import dayjs from 'dayjs'; -import utc from 'dayjs/plugin/utc' -import tz from 'dayjs/plugin/timezone' -dayjs.extend(utc) -dayjs.extend(tz) +import utc from 'dayjs/plugin/utc'; +import tz from 'dayjs/plugin/timezone'; +dayjs.extend(utc); +dayjs.extend(tz); import { Button, ConfigProvider, Form, Modal } from 'antd'; import { useForm } from 'antd/es/form/Form'; @@ -35,16 +42,35 @@ import TransactionLinksApi from '@/app/api/transactions/transactLinks.api'; import FRONTEND_ROUTES from '@/app/common/constants/frontend-routes.constants'; import { removeHtmlTags } from '@/app/common/utils/removeHtmlTags.utility'; import QUILL_TEXTS_LENGTH from '@/features/AdminPage/NewStreetcode/TextBlock/TextLengthConstants/textMaxLength.constant'; -import Subtitle, { SubtitleCreate } from '@/models/additional-content/subtitles.model'; -import { StreetcodeTag, StreetcodeTagUpdate } from '@/models/additional-content/tag.model'; +import Subtitle, { + SubtitleCreate, +} from '@/models/additional-content/subtitles.model'; +import { + StreetcodeTag, + StreetcodeTagUpdate, +} from '@/models/additional-content/tag.model'; import StatisticRecord from '@/models/analytics/statisticrecord.model'; import { AudioUpdate } from '@/models/media/audio.model'; import { ImageCreateUpdate, ImageDetails } from '@/models/media/image.model'; import Video, { VideoCreate } from '@/models/media/video.model'; -import { PartnerCreateUpdateShort, PartnerUpdate } from '@/models/partners/partners.model'; -import { StreetcodeCategoryContent, StreetcodeCategoryContentUpdate } from '@/models/sources/sources.model'; -import { StreetcodeCreate, StreetcodeType, StreetcodeUpdate } from '@/models/streetcode/streetcode-types.model'; -import { Fact, Text, TextCreateUpdate } from '@/models/streetcode/text-contents.model'; +import { + PartnerCreateUpdateShort, + PartnerUpdate, +} from '@/models/partners/partners.model'; +import { + StreetcodeCategoryContent, + StreetcodeCategoryContentUpdate, +} from '@/models/sources/sources.model'; +import { + StreetcodeCreate, + StreetcodeType, + StreetcodeUpdate, +} from '@/models/streetcode/streetcode-types.model'; +import { + Fact, + Text, + TextCreateUpdate, +} from '@/models/streetcode/text-contents.model'; import { TransactionLink } from '@/models/transactions/transaction-link.model'; import ARBlock from './ARBlock/ARBlock.component'; @@ -94,10 +120,12 @@ const NewStreetcode = () => { const [funcName, setFuncName] = useState('create'); const [visibleModal, setVisibleModal] = useState(false); const [savedChanges, setSavedChanges] = useState(true); - const navigationString = 'Покинути сторінку? Внесені зміни, можливо, не буде збережено.'; + const navigationString = + 'Покинути сторінку? Внесені зміни, можливо, не буде збережено.'; const [fieldChanges, setFieldChanges] = useState({}); const streetcodeType = useRef(StreetcodeType.Person); - const [allPersistedSourcesAreSet, setAllPersistedSourcesAreSet] = useState(false); + const [allPersistedSourcesAreSet, setAllPersistedSourcesAreSet] = + useState(false); const handleFieldChange = (fieldName: any, value: any) => { setFieldChanges((prevChanges) => ({ @@ -109,7 +137,9 @@ const NewStreetcode = () => { useEffect(() => { if (isPageLoaded) { - const isAnyFieldChanged = Object.values(fieldChanges).some((value) => value !== undefined && value !== ''); + const isAnyFieldChanged = Object.values(fieldChanges).some( + (value) => value !== undefined && value !== '' + ); setSavedChanges(!isAnyFieldChanged); } else { setPageLoaded(true); @@ -119,7 +149,7 @@ const NewStreetcode = () => { usePrompt( savedChanges ? { when: false, message: '' } - : { when: true, message: navigationString }, + : { when: true, message: navigationString } ); const handleTabClosing = () => { console.log('Close tab'); @@ -130,15 +160,27 @@ const NewStreetcode = () => { event.returnValue = navigationString; }; - const validateQuillTexts = (mainText: string | undefined, additionalText: string | undefined) => { + const validateQuillTexts = ( + mainText: string | undefined, + additionalText: string | undefined + ) => { const mainTextWithoutHtml = mainText ? removeHtmlTags(mainText) : ''; - const additionalTextWithoutHtml = additionalText ? removeHtmlTags(additionalText) : ''; - - const tooLongMainText = mainText && mainTextWithoutHtml.length > QUILL_TEXTS_LENGTH.mainTextMaxLength; - const tooLongAdditionalText = additionalText && additionalTextWithoutHtml.length > QUILL_TEXTS_LENGTH.additionalTextMaxLength; + const additionalTextWithoutHtml = additionalText + ? removeHtmlTags(additionalText) + : ''; + + const tooLongMainText = + mainText && + mainTextWithoutHtml.length > QUILL_TEXTS_LENGTH.mainTextMaxLength; + const tooLongAdditionalText = + additionalText && + additionalTextWithoutHtml.length > + QUILL_TEXTS_LENGTH.additionalTextMaxLength; if (tooLongMainText || tooLongAdditionalText) { - throw new Error('The value is too long either in the main text or in the additional text'); + throw new Error( + 'The value is too long either in the main text or in the additional text' + ); } }; @@ -182,18 +224,24 @@ const NewStreetcode = () => { surname: x.lastName, alias: x.alias, streetcodeUrlName: x.transliterationUrl, - streetcodeFirstDate: dayjs.utc(x.eventStartOrPersonBirthDate).local(), - streetcodeSecondDate: x.eventEndOrPersonDeathDate ? dayjs.utc(x.eventEndOrPersonDeathDate).local() : undefined, + streetcodeFirstDate: dayjs + .utc(x.eventStartOrPersonBirthDate) + .local(), + streetcodeSecondDate: x.eventEndOrPersonDeathDate + ? dayjs.utc(x.eventEndOrPersonDeathDate).local() + : undefined, dateString: x.dateString, teaser: x.teaser, }); - const tagsToUpdate: StreetcodeTagUpdate[] = x.tags.map((tag) => ({ - ...tag, - isPersisted: true, - modelState: ModelState.Updated, - streetcodeId: parseId, - })); + const tagsToUpdate: StreetcodeTagUpdate[] = x.tags.map( + (tag) => ({ + ...tag, + isPersisted: true, + modelState: ModelState.Updated, + streetcodeId: parseId, + }) + ); setSelectedTags(tagsToUpdate as StreetcodeTag[]); setFuncName('update'); @@ -201,75 +249,95 @@ const NewStreetcode = () => { VideosApi.getByStreetcodeId(parseId).then((result) => { setVideo(result); - setInputInfo(prevState => ({ + setInputInfo((prevState) => ({ ...prevState, - ["link"]: result.url - })); - + ['link']: result.url, + })); }); RelatedFigureApi.getByStreetcodeId(parseId).then((result) => { - const persistedFigures: RelatedFigureCreateUpdate[] = result.map((item) => ({ - id: item.id, - title: item.title, - isPersisted: true, - modelState: ModelState.Updated, - })); + const persistedFigures: RelatedFigureCreateUpdate[] = + result.map((item) => ({ + id: item.id, + title: item.title, + isPersisted: true, + modelState: ModelState.Updated, + })); setFigures(persistedFigures); }); - PartnersApi.getPartnersToUpdateByStreetcodeId(parseId).then((result) => { - const persistedPartners: PartnerCreateUpdateShort[] = result.map((item) => ({ - id: item.id, - title: item.title, - isPersisted: true, - modelState: ModelState.Updated, - })); - - setPartners(persistedPartners); - }); + PartnersApi.getPartnersToUpdateByStreetcodeId(parseId).then( + (result) => { + const persistedPartners: PartnerCreateUpdateShort[] = + result.map((item) => ({ + id: item.id, + title: item.title, + isPersisted: true, + modelState: ModelState.Updated, + })); + + setPartners(persistedPartners); + } + ); SubtitlesApi.getSubtitlesByStreetcodeId(parseId) .then((resultSubtitle) => { - if (resultSubtitle){ + if (resultSubtitle) { setSubTitle(resultSubtitle); } }) - .catch((error) => { }); - SourcesApi.getCategoriesByStreetcodeId(parseId).then((result) => { - const id = result.map((x) => x.id); - const getAllStreetcodeCategoriesContentRequest = result.map((x) => SourcesApi.getCategoryContentByStreetcodeId(parseId, x.id)); - Promise.all(getAllStreetcodeCategoriesContentRequest).then((x) => { - const newSources: StreetcodeCategoryContent[] = x.map((e) => ({ - sourceLinkCategoryId: e.sourceLinkCategoryId, - streetcodeId: e.streetcodeId, - id: e.id, - text: e.text, - })); - newSources.map((newSource) => { - const existingSource = sourceCreateUpdateStreetcode - .streetcodeCategoryContents.find((s) => s - .sourceLinkCategoryId === newSource.sourceLinkCategoryId); - - if (!existingSource) { - const persistedItem: StreetcodeCategoryContentUpdate = { - ...newSource, - isPersisted: true, - modelState: ModelState.Updated, - }; - - sourceCreateUpdateStreetcode.setItem(persistedItem); - } - }); - }).then(() => { - setAllPersistedSourcesAreSet(true); - }); + .catch((error) => {}); + SourcesApi.getCategoriesByStreetcodeId(parseId).then( + (result) => { + const id = result.map((x) => x.id); + const getAllStreetcodeCategoriesContentRequest = + result.map((x) => + SourcesApi.getCategoryContentByStreetcodeId( + parseId, + x.id + ) + ); + Promise.all(getAllStreetcodeCategoriesContentRequest) + .then((x) => { + const newSources: StreetcodeCategoryContent[] = + x.map((e) => ({ + sourceLinkCategoryId: + e.sourceLinkCategoryId, + streetcodeId: e.streetcodeId, + id: e.id, + text: e.text, + })); + newSources.map((newSource) => { + const existingSource = + sourceCreateUpdateStreetcode.streetcodeCategoryContents.find( + (s) => + s.sourceLinkCategoryId === + newSource.sourceLinkCategoryId + ); + + if (!existingSource) { + const persistedItem: StreetcodeCategoryContentUpdate = + { + ...newSource, + isPersisted: true, + modelState: ModelState.Updated, + }; + + sourceCreateUpdateStreetcode.setItem( + persistedItem + ); + } + }); + }) + .then(() => { + setAllPersistedSourcesAreSet(true); + }); + } + ); + TransactionLinksApi.getByStreetcodeId(parseId).then((res) => { + if (res) { + setArLink(res); + form.setFieldValue('arlink', res.url); + } }); - TransactionLinksApi.getByStreetcodeId(parseId) - .then((res) => { - if (res) { - setArLink(res); - form.setFieldValue('arlink', res.url); - } - }); }); factsStore.fetchFactsByStreetcodeId(parseId); @@ -285,10 +353,18 @@ const NewStreetcode = () => { const firstErrorIndex = errors.findIndex((e) => e.errors.length > 0); if (firstErrorIndex !== -1) { const firstErrorName = String(errors[firstErrorIndex].name); - if (firstErrorName === 'animations' || firstErrorName === 'pictureBlackWhite') { - const containerElement = document.querySelector('.scrollable-container'); + if ( + firstErrorName === 'animations' || + firstErrorName === 'pictureBlackWhite' + ) { + const containerElement = document.querySelector( + '.scrollable-container' + ); if (containerElement) { - containerElement.scrollIntoView({ behavior: 'smooth', block: 'center' }); + containerElement.scrollIntoView({ + behavior: 'smooth', + block: 'center', + }); } } else { form.scrollToField(firstErrorName, { block: 'center' }); @@ -306,199 +382,325 @@ const NewStreetcode = () => { setSavedChanges(true); } } - form.validateFields().then(() => { - data.stopPropagation(); - - const subtitles: SubtitleCreate[] = [{ subtitleText: subTitle?.subtitleText ?? '' }]; - - const videos: VideoCreate[] = [{ url: inputInfo?.link ?? '' }]; - - const text: TextCreateUpdate = { - id: inputInfo?.id ?? 0, - title: inputInfo?.title, - textContent: inputInfo?.textContent ?? " ", - additionalText: - inputInfo?.textContent !== "


" - ? inputInfo?.additionalText === - "

Текст підготовлений спільно з

" - ? "" - : inputInfo?.additionalText - : "", - streetcodeId: parseId, - }; - validateQuillTexts(text.textContent, text.additionalText); - - const streetcode: StreetcodeCreate = { - id: parseId, - index: form.getFieldValue('streetcodeNumber'), - title: form.getFieldValue('mainTitle'), - alias: form.getFieldValue('alias'), - transliterationUrl: form.getFieldValue('streetcodeUrlName'), - arBlockURL: form.getFieldValue('arlink'), - streetcodeType: streetcodeType.current, - eventStartOrPersonBirthDate: dayjs.utc(form.getFieldValue('streetcodeFirstDate')).toDate(), - eventEndOrPersonDeathDate: form.getFieldValue('streetcodeSecondDate') - ? dayjs.utc(form.getFieldValue('streetcodeSecondDate')).toDate() : null, - imagesIds: createUpdateMediaStore.getImageIds(), - audioId: createUpdateMediaStore.audioId, - tags: reindex(selectedTags).map((tag) => ({ ...tag, id: tag.id < 0 ? 0 : tag.id })), - relatedFigures: figures, - text: text.title && text.textContent ? text : null, - timelineItems: timelineItemStore.getTimelineItemArrayToCreate, - facts: reindex(JSON.parse(JSON.stringify(factsStore.getFactArray)) - .map((fact: Fact) => ({ ...fact, id: 0 }))), - coordinates: JSON.parse(JSON.stringify(streetcodeCoordinatesStore.getStreetcodeCoordinateArray)) - .map((coordinate: StreetcodeCoordinate) => ({ ...coordinate, id: 0 })), - partners, - teaser: form.getFieldValue('teaser'), - viewCount: 0, - dateString: form.getFieldValue('dateString'), - arts: artStore.arts.map((a) => ({ ...a})), - streetcodeArtSlides: streetcodeArtSlideStore.getArtSlidesAsDTO(), - subtitles, - firstName: null, - lastName: null, - videos, - status: tempStatus, - toponyms: newStreetcodeInfoStore.selectedToponyms, - streetcodeCategoryContents: - JSON.parse(JSON.stringify(sourceCreateUpdateStreetcode.streetcodeCategoryContents)) - .map((streetcodeCategoryContent: StreetcodeCategoryContent) => ( - { ...streetcodeCategoryContent, id: 0 } - )), - statisticRecords: JSON.parse(JSON.stringify(statisticRecordStore.getStatisticRecordArray)) - .map((statisticRecord: StatisticRecord) => ( - { - ...statisticRecord, - id: 0, - coordinateId: 0, - streetcodeCoordinate: { - ...statisticRecord.streetcodeCoordinate, - id: 0, - }, - } - )), - imagesDetails: createUpdateMediaStore.getImageDetails(), - }; - - if (streetcodeType.current === StreetcodeType.Person) { - streetcode.firstName = form.getFieldValue('name'); - streetcode.lastName = form.getFieldValue('surname'); - } - if (parseId) { - const relatedFiguresUpdate: RelatedFigureUpdate[] = figures.map((figure) => ({ - observerId: parseId, - targetId: figure.id, - modelState: figure.modelState, - })); - - const partnersUpdate: PartnerUpdate[] = partners.map((partner) => ({ - streetcodeId: parseId, - partnerId: partner.id, - modelState: partner.modelState, - })); - - const videosUpdate: Video[] = [{ ...video, url: inputInfo?.link ?? '' } as Video]; - - const subtitleUpdate: Subtitle[] = [ - { ...subTitle, subtitleText: subTitle?.subtitleText ?? '' } as Subtitle]; - - const tags = [...(reindex(selectedTags) as StreetcodeTagUpdate[]) - .map((tag) => ({ ...tag, streetcodeId: parseId })), - ...tagsStore.getTagToDeleteArray]; - - const arUrl = form.getFieldValue('arlink'); - const arLinkUpdated: TransactionLink = { - id: arLink?.id ?? 0, + form.validateFields() + .then(() => { + data.stopPropagation(); + + const subtitles: SubtitleCreate[] = [ + { subtitleText: subTitle?.subtitleText ?? '' }, + ]; + + const videos: VideoCreate[] = [{ url: inputInfo?.link ?? '' }]; + + const text: TextCreateUpdate = { + id: inputInfo?.id ?? 0, + title: inputInfo?.title, + textContent: inputInfo?.textContent ?? ' ', + additionalText: + inputInfo?.textContent !== '


' + ? inputInfo?.additionalText === + '

Текст підготовлений спільно з

' + ? '' + : inputInfo?.additionalText + : '', streetcodeId: parseId, - url: arLink?.url ?? '', - urlTitle: arLink?.urlTitle ?? '', }; + validateQuillTexts(text.textContent, text.additionalText); - if (text.id !== 0 && !(text.title && text.textContent)) { - text.modelState = ModelState.Deleted; - } + const usedArts = streetcodeArtSlideStore + .getArtSlidesAsDTO() + .filter((slide) => slide.modelState !== ModelState.Deleted) + .flatMap((slide) => slide.streetcodeArts); + + const filteredArts = artStore.arts.filter((art) => + usedArts.some((usedArt) => usedArt.artId === art.id) + ); - const streetcodeUpdate: StreetcodeUpdate = { + const streetcode: StreetcodeCreate = { id: parseId, index: form.getFieldValue('streetcodeNumber'), - firstName: null, - lastName: null, title: form.getFieldValue('mainTitle'), alias: form.getFieldValue('alias'), - status: tempStatus, transliterationUrl: form.getFieldValue('streetcodeUrlName'), + arBlockURL: form.getFieldValue('arlink'), streetcodeType: streetcodeType.current, - eventStartOrPersonBirthDate: dayjs.utc(form.getFieldValue('streetcodeFirstDate')).toDate(), - eventEndOrPersonDeathDate: form.getFieldValue('streetcodeSecondDate') - ? dayjs.utc(form.getFieldValue('streetcodeSecondDate')).toDate() : null, + eventStartOrPersonBirthDate: dayjs + .utc(form.getFieldValue('streetcodeFirstDate')) + .toDate(), + eventEndOrPersonDeathDate: form.getFieldValue( + 'streetcodeSecondDate' + ) + ? dayjs + .utc(form.getFieldValue('streetcodeSecondDate')) + .toDate() + : null, + imagesIds: createUpdateMediaStore.getImageIds(), + audioId: createUpdateMediaStore.audioId, + tags: reindex(selectedTags).map((tag) => ({ + ...tag, + id: tag.id < 0 ? 0 : tag.id, + })), + relatedFigures: figures, + text: text.title && text.textContent ? text : null, + timelineItems: + timelineItemStore.getTimelineItemArrayToCreate, + facts: reindex( + JSON.parse(JSON.stringify(factsStore.getFactArray)).map( + (fact: Fact) => ({ ...fact, id: 0 }) + ) + ), + coordinates: JSON.parse( + JSON.stringify( + streetcodeCoordinatesStore.getStreetcodeCoordinateArray + ) + ).map((coordinate: StreetcodeCoordinate) => ({ + ...coordinate, + id: 0, + })), + partners, teaser: form.getFieldValue('teaser'), + viewCount: 0, dateString: form.getFieldValue('dateString'), - videos: videosUpdate, - relatedFigures: relatedFiguresUpdate, - timelineItems: timelineItemStore.getTimelineItemArrayToUpdate, - facts: reindex(factsStore.getFactArrayToUpdate.map((item) => ({ ...item, - streetcodeId: parseId, - id: item.id < 0 ? 0 : item.id }))), - partners: partnersUpdate, - subtitles: subtitleUpdate, - text: text.modelState === ModelState.Deleted || (text.title && text.textContent) ? text : null, - streetcodeCategoryContents: sourceCreateUpdateStreetcode.getCategoryContentsArrayToUpdate - .map((content) => ({ ...content, streetcodeId: parseId })), - arts: artStore.arts, - streetcodeArtSlides: streetcodeArtSlideStore.getArtSlidesAsDTO(), - tags: tags.map((tag) => ({ ...tag, id: tag.id < 0 ? 0 : tag.id })), - statisticRecords: statisticRecordStore.getStatisticRecordArrayToUpdate - .map((record) => ({ ...record, streetcodeId: parseId })), + arts: filteredArts, + streetcodeArtSlides: + streetcodeArtSlideStore.getArtSlidesAsDTO(), + subtitles, + firstName: null, + lastName: null, + videos, + status: tempStatus, toponyms: newStreetcodeInfoStore.selectedToponyms, - images: createUpdateMediaStore.imagesUpdate.map((img): ImageCreateUpdate => ({ id: img.id, modelState: img.modelState, streetcodeId: img.streetcodeId })), - audioId: createUpdateMediaStore.audioId, - audios: createUpdateMediaStore.audioUpdate.map((a): AudioUpdate => ({ id: a.id, modelState: a.modelState, streetcodeId: a.streetcodeId })), - transactionLink: { - id: arLink?.id ?? 0, - streetcodeId: parseId, - url: form.getFieldValue('arlink') ?? '', - qrCodeUrl: arLink?.urlTitle ?? '', - modelState: 0, - }, - imagesDetails: (Array.from(factsStore.factImageDetailsMap.values()) as ImageDetails[]).concat(createUpdateMediaStore.getImageDetailsUpdate()), + streetcodeCategoryContents: JSON.parse( + JSON.stringify( + sourceCreateUpdateStreetcode.streetcodeCategoryContents + ) + ).map( + ( + streetcodeCategoryContent: StreetcodeCategoryContent + ) => ({ + ...streetcodeCategoryContent, + id: 0, + }) + ), + statisticRecords: JSON.parse( + JSON.stringify( + statisticRecordStore.getStatisticRecordArray + ) + ).map((statisticRecord: StatisticRecord) => ({ + ...statisticRecord, + id: 0, + coordinateId: 0, + streetcodeCoordinate: { + ...statisticRecord.streetcodeCoordinate, + id: 0, + }, + })), + imagesDetails: createUpdateMediaStore.getImageDetails(), }; if (streetcodeType.current === StreetcodeType.Person) { - streetcodeUpdate.firstName = form.getFieldValue('name'); - streetcodeUpdate.lastName = form.getFieldValue('surname'); + streetcode.firstName = form.getFieldValue('name'); + streetcode.lastName = form.getFieldValue('surname'); } - StreetcodesApi.update(streetcodeUpdate).then(() => { - window.location.reload(); - }).then(() => { - alert('Cтріткод успішно оновлений'); - }) - .catch((error2) => { - alert('Виникла помилка при оновленні стріткоду'); - }); - } else { - console.log(streetcode); - StreetcodesApi.create(streetcode) - .then(() => { - streetcodeArtSlideStore.streetcodeArtSlides = []; - if (tempStatus === 1) { - navigate(`../${form.getFieldValue('streetcodeUrlName')}`, { replace: true }); - } else { - navigate(`${FRONTEND_ROUTES.ADMIN.BASE}/${form.getFieldValue('streetcodeUrlName')}`); - } - }) - .catch((error) => { - alert('Виникла помилка при створенні стріткоду'); - }); - } - }).catch(() => { - const name = form.getFieldsError().find((e) => e.errors.length > 0)?.name; - if (name) { - scrollToErrors(); - } else { - alert('Будь ласка, заповніть всі поля валідними даними'); - } - }); + if (parseId) { + const relatedFiguresUpdate: RelatedFigureUpdate[] = + figures.map((figure) => ({ + observerId: parseId, + targetId: figure.id, + modelState: figure.modelState, + })); + + const partnersUpdate: PartnerUpdate[] = partners.map( + (partner) => ({ + streetcodeId: parseId, + partnerId: partner.id, + modelState: partner.modelState, + }) + ); + + const videosUpdate: Video[] = [ + { ...video, url: inputInfo?.link ?? '' } as Video, + ]; + + const subtitleUpdate: Subtitle[] = [ + { + ...subTitle, + subtitleText: subTitle?.subtitleText ?? '', + } as Subtitle, + ]; + + const tags = [ + ...(reindex(selectedTags) as StreetcodeTagUpdate[]).map( + (tag) => ({ + ...tag, + streetcodeId: parseId, + }) + ), + ...tagsStore.getTagToDeleteArray, + ]; + + const arUrl = form.getFieldValue('arlink'); + const arLinkUpdated: TransactionLink = { + id: arLink?.id ?? 0, + streetcodeId: parseId, + url: arLink?.url ?? '', + urlTitle: arLink?.urlTitle ?? '', + }; + + if (text.id !== 0 && !(text.title && text.textContent)) { + text.modelState = ModelState.Deleted; + } + + const streetcodeUpdate: StreetcodeUpdate = { + id: parseId, + index: form.getFieldValue('streetcodeNumber'), + firstName: null, + lastName: null, + title: form.getFieldValue('mainTitle'), + alias: form.getFieldValue('alias'), + status: tempStatus, + transliterationUrl: + form.getFieldValue('streetcodeUrlName'), + streetcodeType: streetcodeType.current, + eventStartOrPersonBirthDate: dayjs + .utc(form.getFieldValue('streetcodeFirstDate')) + .toDate(), + eventEndOrPersonDeathDate: form.getFieldValue( + 'streetcodeSecondDate' + ) + ? dayjs + .utc( + form.getFieldValue('streetcodeSecondDate') + ) + .toDate() + : null, + teaser: form.getFieldValue('teaser'), + dateString: form.getFieldValue('dateString'), + videos: videosUpdate, + relatedFigures: relatedFiguresUpdate, + timelineItems: + timelineItemStore.getTimelineItemArrayToUpdate, + facts: reindex( + factsStore.getFactArrayToUpdate.map((item) => ({ + ...item, + streetcodeId: parseId, + id: item.id < 0 ? 0 : item.id, + })) + ), + partners: partnersUpdate, + subtitles: subtitleUpdate, + text: + text.modelState === ModelState.Deleted || + (text.title && text.textContent) + ? text + : null, + streetcodeCategoryContents: + sourceCreateUpdateStreetcode.getCategoryContentsArrayToUpdate.map( + (content) => ({ + ...content, + streetcodeId: parseId, + }) + ), + arts: filteredArts, + streetcodeArtSlides: + streetcodeArtSlideStore.getArtSlidesAsDTO(), + tags: tags.map((tag) => ({ + ...tag, + id: tag.id < 0 ? 0 : tag.id, + })), + statisticRecords: + statisticRecordStore.getStatisticRecordArrayToUpdate.map( + (record) => ({ + ...record, + streetcodeId: parseId, + }) + ), + toponyms: newStreetcodeInfoStore.selectedToponyms, + images: createUpdateMediaStore.imagesUpdate.map( + (img): ImageCreateUpdate => ({ + id: img.id, + modelState: img.modelState, + streetcodeId: img.streetcodeId, + }) + ), + audioId: createUpdateMediaStore.audioId, + audios: createUpdateMediaStore.audioUpdate.map( + (a): AudioUpdate => ({ + id: a.id, + modelState: a.modelState, + streetcodeId: a.streetcodeId, + }) + ), + transactionLink: { + id: arLink?.id ?? 0, + streetcodeId: parseId, + url: form.getFieldValue('arlink') ?? '', + qrCodeUrl: arLink?.urlTitle ?? '', + modelState: 0, + }, + imagesDetails: ( + Array.from( + factsStore.factImageDetailsMap.values() + ) as ImageDetails[] + ).concat( + createUpdateMediaStore.getImageDetailsUpdate() + ), + }; + + if (streetcodeType.current === StreetcodeType.Person) { + streetcodeUpdate.firstName = form.getFieldValue('name'); + streetcodeUpdate.lastName = + form.getFieldValue('surname'); + } + StreetcodesApi.update(streetcodeUpdate) + .then(() => { + window.location.reload(); + }) + .then(() => { + alert('Cтріткод успішно оновлений'); + }) + .catch((error2) => { + alert('Виникла помилка при оновленні стріткоду'); + }); + } else { + console.log(streetcode); + StreetcodesApi.create(streetcode) + .then(() => { + streetcodeArtSlideStore.streetcodeArtSlides = []; + if (tempStatus === 1) { + navigate( + `../${form.getFieldValue( + 'streetcodeUrlName' + )}`, + { + replace: true, + } + ); + } else { + navigate( + `${ + FRONTEND_ROUTES.ADMIN.BASE + }/${form.getFieldValue( + 'streetcodeUrlName' + )}` + ); + } + }) + .catch((error) => { + alert('Виникла помилка при створенні стріткоду'); + }); + } + }) + .catch(() => { + const name = form + .getFieldsError() + .find((e) => e.errors.length > 0)?.name; + if (name) { + scrollToErrors(); + } else { + alert('Будь ласка, заповніть всі поля валідними даними'); + } + }); }; const handleModalOk = (data: any) => { setSavedChanges(true); @@ -512,7 +714,12 @@ const NewStreetcode = () => {

Стріткод

-
+ { setVideo={setVideo} onChange={handleFieldChange} /> - + - - + + - - - - + + + +
diff --git a/src/features/AdminPage/NewStreetcode/MainNewStreetcode.styles.scss b/src/features/AdminPage/NewStreetcode/MainNewStreetcode.styles.scss index 876c03be9..94dc672c3 100644 --- a/src/features/AdminPage/NewStreetcode/MainNewStreetcode.styles.scss +++ b/src/features/AdminPage/NewStreetcode/MainNewStreetcode.styles.scss @@ -29,6 +29,11 @@ $articlesImg: "@assets/images/sources/Articles.webp"; margin-bottom: f.pxToRem(7px); } + h4{ + font-weight: 300; + color: c.$accented-red-color; + } + .buttonWithPlus{ @include mut.sized($width: 150px, $height: 50px); border: 1.5px solid c.$dark-red-color; diff --git a/src/features/AdminPage/NewStreetcode/StreetcodeArtsBlock/StreetcodeArtsBlock.component.tsx b/src/features/AdminPage/NewStreetcode/StreetcodeArtsBlock/StreetcodeArtsBlock.component.tsx index 5089b7e71..393941710 100644 --- a/src/features/AdminPage/NewStreetcode/StreetcodeArtsBlock/StreetcodeArtsBlock.component.tsx +++ b/src/features/AdminPage/NewStreetcode/StreetcodeArtsBlock/StreetcodeArtsBlock.component.tsx @@ -7,6 +7,7 @@ const StreetcodeArtsBlock = React.memo(() => (

Арт-галерея

Завантажити арти

+

* Зауважте, не використані арти видаляються

)); export default StreetcodeArtsBlock;