Skip to content

Commit

Permalink
Merge pull request #9 from dmytro-komlyk/deployment
Browse files Browse the repository at this point in the history
refactor: fixed slug logic
  • Loading branch information
dmytro-komlyk authored Feb 27, 2024
2 parents cc83739 + 01fa44e commit 42f6354
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 48 deletions.
23 changes: 2 additions & 21 deletions apps/admin/app/(pages)/articles/(components)/AddArticleSection.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use client'

import { createSlug } from '@admin/app/(utils)/createSlug'
import { trpc } from '@admin/app/(utils)/trpc/client'
import { uploadImg } from '@admin/app/api/service/image/uploadImg'
import {
Expand Down Expand Up @@ -60,7 +61,7 @@ const AddArticleSection = ({ allImagesData }: { allImagesData: IImage[] }) => {
setSubmitting(true)
const { file, ...restValues } = values
const articleValues = {
slug: restValues.slug,
slug: createSlug(restValues.title),
title: restValues.title,
preview: restValues.preview,
text: restValues.content,
Expand Down Expand Up @@ -116,7 +117,6 @@ const AddArticleSection = ({ allImagesData }: { allImagesData: IImage[] }) => {
seoTitle: '',
seoDescription: '',
seoKeywords: '',
slug: '',
title: '',
preview: '',
file: null,
Expand All @@ -126,7 +126,6 @@ const AddArticleSection = ({ allImagesData }: { allImagesData: IImage[] }) => {
seoTitle: Yup.string().min(1).required('Введіть заголовок'),
seoDescription: Yup.string().min(1).required('Введіть опис'),
seoKeywords: Yup.string().min(1).required('Введіть ключі'),
slug: Yup.string().min(3).required('Введіть ЧПУ'),
title: Yup.string().min(1).required('Введіть заголовок'),
preview: Yup.string().min(1).required('Введіть опис'),
file: Yup.mixed().required('Додайте зображення'),
Expand Down Expand Up @@ -201,24 +200,6 @@ const AddArticleSection = ({ allImagesData }: { allImagesData: IImage[] }) => {
</CardBody>
</Card>
<div className='order-1 flex h-72 w-[45%] flex-col justify-end gap-4'>
<Field name='slug'>
{({ meta, field }: any) => (
<Input
type='text'
label='ЧПУ(slug)'
labelPlacement='inside'
variant='bordered'
isInvalid={!!(meta.touched && meta.error)}
errorMessage={meta.touched && meta.error && meta.error}
classNames={{
label: ['font-base', 'text-md', 'text-black-dis'],
input: ['font-base', 'text-md', 'text-black-dis'],
inputWrapper: ['bg-white-dis'],
}}
{...field}
/>
)}
</Field>
<Field name='title'>
{({ meta, field }: any) => (
<Input
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ const EditArticleSection = ({
})
}
} catch (err) {
console.log(err)
toast.error(`Виникла помилка при додаванні...`, {
style: {
borderRadius: '10px',
Expand Down Expand Up @@ -130,7 +129,6 @@ const EditArticleSection = ({
seoTitle: Yup.string().min(1).required('Введіть заголовок'),
seoDescription: Yup.string().min(1).required('Введіть опис'),
seoKeywords: Yup.string().min(1).required('Введіть ключі'),
slug: Yup.string().min(3).required('Введіть ЧПУ'),
title: Yup.string().min(1).required('Введіть заголовок'),
preview: Yup.string().min(1).required('Введіть опис'),
file: Yup.mixed().required('Додайте зображення'),
Expand Down Expand Up @@ -208,6 +206,7 @@ const EditArticleSection = ({
<Field name='slug'>
{({ meta, field }: any) => (
<Input
isDisabled
type='text'
label='ЧПУ(slug)'
labelPlacement='inside'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client'

import { SERVER_URL } from '@admin/app/(lib)/constants'
import { createSlug } from '@admin/app/(utils)/createSlug'
import { trpc } from '@admin/app/(utils)/trpc/client'
import { uploadImg } from '@admin/app/api/service/image/uploadImg'
import {
Expand Down Expand Up @@ -110,7 +111,7 @@ const EditGadgetForm = ({
setSubmitting(true)
const { file, ...restValues } = values
const gadgetValues = {
slug: restValues.slug,
slug: createSlug(restValues.title),
title: restValues.title,
description: restValues.description,
metadata: {
Expand Down Expand Up @@ -174,7 +175,6 @@ const EditGadgetForm = ({
seoKeywords: Yup.string().min(1).required('Введіть ключі'),
title: Yup.string().min(1).required('Введіть заголовок'),
description: Yup.string().min(1).required('Введіть опис'),
slug: Yup.string().min(3).required('Введіть ЧПУ'),
})}
onSubmit={handleSubmit}
>
Expand Down Expand Up @@ -267,6 +267,7 @@ const EditGadgetForm = ({
<Field name='slug'>
{({ meta, field }: any) => (
<Input
isDisabled
type='text'
label='ЧПУ(slug)'
labelPlacement='inside'
Expand Down
23 changes: 2 additions & 21 deletions apps/admin/app/(pages)/issues/(components)/AddIssueInfoSection.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use client'

import { createSlug } from '@admin/app/(utils)/createSlug'
import { trpc } from '@admin/app/(utils)/trpc/client'
import { uploadImg } from '@admin/app/api/service/image/uploadImg'
import {
Expand Down Expand Up @@ -70,7 +71,7 @@ const AddIssueInfoSection = ({
setSubmitting(true)
const { file, ...restValues } = values
const issueValues = {
slug: restValues.slug,
slug: createSlug(restValues.title),
price: restValues.price,
title: restValues.title,
info: restValues.info,
Expand Down Expand Up @@ -132,7 +133,6 @@ const AddIssueInfoSection = ({
seoKeywords: '',
title: '',
price: '',
slug: '',
file: null,
info: '',
description: '',
Expand All @@ -143,7 +143,6 @@ const AddIssueInfoSection = ({
seoKeywords: Yup.string().min(1).required('Введіть ключі'),
title: Yup.string().min(1).required('Введіть заголовок'),
price: Yup.string().min(1).required('Введіть вартість'),
slug: Yup.string().min(3).required('Введіть ЧПУ'),
file: Yup.mixed().required('Додайте зображення'),
info: Yup.string().min(1).required('Введіть контент'),
description: Yup.string().min(1).required('Введіть контент'),
Expand Down Expand Up @@ -217,24 +216,6 @@ const AddIssueInfoSection = ({
</CardBody>
</Card>
<div className='order-1 flex h-72 w-[45%] flex-col justify-end gap-4'>
<Field name='slug'>
{({ meta, field }: any) => (
<Input
type='text'
label='ЧПУ(slug)'
labelPlacement='inside'
variant='bordered'
isInvalid={!!(meta.touched && meta.error)}
errorMessage={meta.touched && meta.error && meta.error}
classNames={{
label: ['font-base', 'text-md', 'text-black-dis'],
input: ['font-base', 'text-md', 'text-black-dis'],
inputWrapper: ['bg-white-dis'],
}}
{...field}
/>
)}
</Field>
<Field name='price'>
{({ meta, field }: any) => (
<Input
Expand Down
5 changes: 3 additions & 2 deletions apps/admin/app/(pages)/issues/(components)/EditIssueForm.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client'

import { SERVER_URL } from '@admin/app/(lib)/constants'
import { createSlug } from '@admin/app/(utils)/createSlug'
import { trpc } from '@admin/app/(utils)/trpc/client'
import { uploadImg } from '@admin/app/api/service/image/uploadImg'
import { Card, CardBody, CardHeader, Input, Tab, Tabs } from '@nextui-org/react'
Expand Down Expand Up @@ -78,7 +79,7 @@ const EditIssuesForm = ({
const { file, ...restValues } = values

const issueValues = {
slug: restValues.slug,
slug: createSlug(restValues.title),
price: restValues.price,
title: restValues.title,
info: restValues.info,
Expand Down Expand Up @@ -140,7 +141,6 @@ const EditIssuesForm = ({
seoKeywords: Yup.string().min(1).required('Введіть ключі'),
title: Yup.string().min(1).required('Введіть заголовок'),
price: Yup.string().min(1).required('Введіть вартість'),
slug: Yup.string().min(3).required('Введіть ЧПУ'),
info: Yup.string().min(1).required('Введіть контент'),
description: Yup.string().min(1).required('Введіть контент'),
})}
Expand Down Expand Up @@ -216,6 +216,7 @@ const EditIssuesForm = ({
<Field name='slug'>
{({ meta, field }: any) => (
<Input
isDisabled
type='text'
label='ЧПУ(slug)'
labelPlacement='inside'
Expand Down

0 comments on commit 42f6354

Please sign in to comment.