Skip to content

feat: toaster and eslint config added #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

yuriassuncx
Copy link

Qual o objetivo deste PR?

  • Padronizar linhas de códigos por meio da configuração do eslint da Rocketseat;
  • Adicionar um toaster para melhorar a experiência do usuário e tornar o site mais interativo/dinâmico;

Na prática:

WhatsApp Image 2023-06-20 at 13 53 31

WhatsApp Image 2023-06-20 at 13 53 20

Adicionado o toaster na função handleChange do cart-item.tsx:

const handleChange = (e: ChangeEvent<HTMLSelectElement>) => {
    handleUpdateQuantity(product.id, Number(e.target.value))
    toast.success(
      `Quantidade do ${product.name} alterada para ${e.target.value}`,
      {
        position: 'bottom-center',
      },
    )
  }

Adicionado o toaster na função handleAddToCart da página do produto:

const handleAddToCart = () => {
    const cartItems = localStorage.getItem('cart-items')
    if (cartItems) {
      const cartItemsArray = JSON.parse(cartItems)

      const existingProductIndex = cartItemsArray.findIndex(
        (item: { id: string }) => item.id === searchParams.id,
      )

      if (existingProductIndex !== -1) {
        cartItemsArray[existingProductIndex].quantity += 1
      } else {
        cartItemsArray.push({ ...data, quantity: 1, id: searchParams.id })
      }

      localStorage.setItem('cart-items', JSON.stringify(cartItemsArray))
    } else {
      const newCart = [{ ...data, quantity: 1, id: searchParams.id }]
      localStorage.setItem('cart-items', JSON.stringify(newCart))
    }

    toast.success('Produto adicionado ao carrinho', {
      position: 'bottom-center',
    })
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant