generated from ita-social-projects/DevTemplate
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
67 additions
and
60 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
src/app/common/components/modals/validators/socialLinkValidator.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* eslint-disable import/extensions */ | ||
|
||
import { doesUrlContainSiteName, isInvalidUrl } from '@/app/common/utils/checkUrl'; | ||
import SocialItem from '@/models/social-link/socialItem'; | ||
|
||
export default function validateSocialLink<T>( | ||
link: string, | ||
socialOptions: SocialItem<T>[], | ||
logoTypes: string[], | ||
sourceLinks: { logoType: T }[], | ||
socialName: string, | ||
): Promise<unknown> { | ||
if (!link || isInvalidUrl(link)) { | ||
return Promise.reject(new Error( | ||
'Недійсний формат посилання', | ||
)); | ||
} | ||
|
||
const logotype = socialOptions.find((opt) => opt.value === socialName)?.logo; | ||
if (logotype === undefined // we need this explicit check because it can pass when logotype is 0 | ||
|| logotype === null | ||
|| (!doesUrlContainSiteName(link, logoTypes[Number(logotype)]))) { | ||
return Promise.reject(new Error( | ||
'Посилання не співпадає з вибраним текстом', | ||
)); | ||
} | ||
|
||
const doesLinkWithLogoTypeAlreadyExist = sourceLinks.some((obj) => obj.logoType === Number(logotype)); | ||
if (doesLinkWithLogoTypeAlreadyExist) { | ||
return Promise.reject(new Error( | ||
'Посилання на таку соціальну мережу вже додано', | ||
)); | ||
} | ||
|
||
return Promise.resolve(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 4 additions & 7 deletions
11
src/features/AdminPage/PartnersPage/PartnerModal/constants/socialOptions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 4 additions & 6 deletions
10
src/features/AdminPage/TeamPage/TeamModal/constants/socialOptions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default interface SocialItem<T> { | ||
label: string | ||
value: string | ||
logo: T | ||
} |