Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ import {
Stack,
Text,
} from '@chakra-ui/react'
import { TextBubbleContent, Variable, WhatsAppButtonsListOptions, WhatsAppButtonsListStep, StepWithItems, StepIndices, ItemType } from 'models'
import {
TextBubbleContent,
Variable,
WhatsAppButtonsListOptions,
WhatsAppButtonsListStep,
StepWithItems,
StepIndices,
ItemType,
} from 'models'
import { useState } from 'react'
import { TextBubbleEditor } from 'components/shared/Graph/Nodes/StepNode/TextBubbleEditor'
import { VariableSearchInput } from 'components/shared/VariableSearchInput/VariableSearchInput'
Expand Down Expand Up @@ -156,8 +164,9 @@ export const WhatsAppButtonsListSettingsBody = ({
</FormLabel>
<TextBubbleEditor
required={{
errorMsg: `O campo "Mensagem para resposta inválida - Tentativa ${index + 1
}" é obrigatório`,
errorMsg: `O campo "Mensagem para resposta inválida - Tentativa ${
index + 1
}" é obrigatório`,
}}
onClose={(content) => handleFallBackMessage(content, index)}
initialValue={message ? message.richText : []}
Expand Down Expand Up @@ -203,7 +212,9 @@ export const WhatsAppButtonsListSettingsBody = ({
const handleRemoveButton = (index: number) => {
if (localListItems.length <= 1) return

const updatedItems = localListItems.filter((_: any, i: number) => i !== index)
const updatedItems = localListItems.filter(
(_: any, i: number) => i !== index
)

setLocalListItems(updatedItems)
onOptionsChange({ ...options, buttonItems: updatedItems })
Expand Down Expand Up @@ -273,7 +284,9 @@ export const WhatsAppButtonsListSettingsBody = ({
step={step as StepWithItems}
indices={indices}
isReadOnly={false}
handleUpdateItem={(_, itemIndex, value) => handleUpdateButton(itemIndex, value)}
handleUpdateItem={(_, itemIndex, value) =>
handleUpdateButton(itemIndex, value)
}
handleRemoveItem={(_, itemIndex) => handleRemoveButton(itemIndex)}
handleReorderItem={handleReorderButton}
/>
Expand All @@ -285,11 +298,19 @@ export const WhatsAppButtonsListSettingsBody = ({
onClick={handleAddButton}
variant="outline"
size="md"
color={localListItems.length >= MAX_BUTTONS ? 'gray.400' : '#1366C9'}
borderColor={localListItems.length >= MAX_BUTTONS ? 'gray.300' : '#1366C9'}
color={
localListItems.length >= MAX_BUTTONS ? 'gray.400' : '#1366C9'
}
borderColor={
localListItems.length >= MAX_BUTTONS ? 'gray.300' : '#1366C9'
}
borderWidth="2px"
fontSize="sm"
_hover={localListItems.length >= MAX_BUTTONS ? {} : { bg: '#1366C9', color: 'white' }}
_hover={
localListItems.length >= MAX_BUTTONS
? {}
: { bg: '#1366C9', color: 'white' }
}
_disabled={{ opacity: 1, cursor: 'not-allowed' }}
isDisabled={localListItems.length >= MAX_BUTTONS}
>
Expand All @@ -298,7 +319,11 @@ export const WhatsAppButtonsListSettingsBody = ({
</Flex>
</Stack>

{options?.useFallback && localListItems.length > 0 && localListItems.some((item: any) => item.text && item.text.trim() !== '') &&
{options?.useFallback &&
localListItems.length > 0 &&
localListItems.some(
(item: any) => item.text && item.text.trim() !== ''
) &&
(options?.fallbackMessages?.length ? (
<>
<Flex justifyContent={'space-between'} alignItems={'center'}>
Expand All @@ -318,7 +343,12 @@ export const WhatsAppButtonsListSettingsBody = ({
fallbackMessageComponent(message, index)
)}
<Box>
<FormLabel mb="0" htmlFor="placeholder" fontWeight="bold" fontSize="sm">
<FormLabel
mb="0"
htmlFor="placeholder"
fontWeight="bold"
fontSize="sm"
>
Se o cliente errar 3 vezes seguidas, atribuir conversa para:
</FormLabel>
<AssignToResponsibleSelect
Expand All @@ -339,7 +369,12 @@ export const WhatsAppButtonsListSettingsBody = ({
))}
<Stack>
<Flex>
<FormLabel mb="0" htmlFor="footer-input" fontWeight="bold" fontSize={'sm'}>
<FormLabel
mb="0"
htmlFor="footer-input"
fontWeight="bold"
fontSize={'sm'}
>
Texto do rodapé
</FormLabel>
<Spacer />
Expand All @@ -359,7 +394,9 @@ export const WhatsAppButtonsListSettingsBody = ({
</Stack>
<Stack>
<VariableSearchInput
initialVariableId={options.variableId || (step as any)?.initialVariableToken}
initialVariableId={
options.variableId || (step as any)?.initialVariableToken
}
onSelectVariable={handleVariableChange}
/>
</Stack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ import {
Stack,
Text,
} from '@chakra-ui/react'
import { WhatsAppOptionsListOptions, Variable, TextBubbleContent, WhatsAppOptionsListStep, StepWithItems, ItemType } from 'models'
import {
WhatsAppOptionsListOptions,
Variable,
TextBubbleContent,
WhatsAppOptionsListStep,
StepWithItems,
ItemType,
} from 'models'
import { useState } from 'react'
import { TextBubbleEditor } from 'components/shared/Graph/Nodes/StepNode/TextBubbleEditor'
import { VariableSearchInput } from 'components/shared/VariableSearchInput/VariableSearchInput'
Expand Down Expand Up @@ -63,7 +70,7 @@ export const WhatsAppOptionsListSettingsBody = ({

const MAX_LENGHT_HEADER_AND_FOOTER = 60
const MAX_LENGHT_BODY = 1024
const MAX_LENGHT_LIST_TITLE = 30
const MAX_LENGHT_LIST_TITLE = 20
const MAX_OPTIONS = 10

const handleVariableChange = (variable?: Variable) => {
Expand Down Expand Up @@ -174,8 +181,9 @@ export const WhatsAppOptionsListSettingsBody = ({
</FormLabel>
<TextBubbleEditor
required={{
errorMsg: `O campo "Mensagem para resposta inválida - Tentativa ${index + 1
}" é obrigatório`,
errorMsg: `O campo "Mensagem para resposta inválida - Tentativa ${
index + 1
}" é obrigatório`,
}}
onClose={(content) => handleFallBackMessage(content, index)}
initialValue={message ? message.richText : []}
Expand Down Expand Up @@ -225,7 +233,9 @@ export const WhatsAppOptionsListSettingsBody = ({
const handleRemoveOption = (index: number) => {
if (localListItems.length <= 1) return

const updatedItems = localListItems.filter((_: any, i: number) => i !== index)
const updatedItems = localListItems.filter(
(_: any, i: number) => i !== index
)

setLocalListItems(updatedItems)
onOptionsChange({ ...options, listItems: updatedItems })
Expand Down Expand Up @@ -284,11 +294,17 @@ export const WhatsAppOptionsListSettingsBody = ({
maxLength={MAX_LENGHT_BODY}
/>
</Stack>
{options?.useFallback && localListItems.length > 0 && localListItems.some((item: any) => item.label && item.label.trim() !== '') &&
{options?.useFallback &&
localListItems.length > 0 &&
localListItems.some(
(item: any) => item.label && item.label.trim() !== ''
) &&
(options?.fallbackMessages?.length ? (
<>
<Flex justifyContent={'space-between'} alignItems={'center'}>
<Text fontWeight="bold" fontSize="sm">Se o cliente não responder com nenhuma das opções:</Text>
<Text fontWeight="bold" fontSize="sm">
Se o cliente não responder com nenhuma das opções:
</Text>
<Button
background={'transparent'}
onClick={() => setIsCollapsed((v) => !v)}
Expand All @@ -302,7 +318,12 @@ export const WhatsAppOptionsListSettingsBody = ({
fallbackMessageComponent(message, index)
)}
<Box>
<FormLabel mb="0" htmlFor="placeholder" fontWeight="bold" fontSize="sm">
<FormLabel
mb="0"
htmlFor="placeholder"
fontWeight="bold"
fontSize="sm"
>
Se o cliente errar 3 vezes seguidas, atribuir conversa para:
</FormLabel>
<AssignToResponsibleSelect
Expand Down Expand Up @@ -356,7 +377,9 @@ export const WhatsAppOptionsListSettingsBody = ({
step={step as StepWithItems}
indices={indices}
isReadOnly={false}
handleUpdateItem={(_, itemIndex, value) => handleUpdateOption(itemIndex, value)}
handleUpdateItem={(_, itemIndex, value) =>
handleUpdateOption(itemIndex, value)
}
handleRemoveItem={(_, itemIndex) => handleRemoveOption(itemIndex)}
handleReorderItem={handleReorderOption}
/>
Expand All @@ -368,11 +391,19 @@ export const WhatsAppOptionsListSettingsBody = ({
onClick={handleAddOption}
variant="outline"
size="md"
color={localListItems.length >= MAX_OPTIONS ? 'gray.400' : '#1366C9'}
borderColor={localListItems.length >= MAX_OPTIONS ? 'gray.300' : '#1366C9'}
color={
localListItems.length >= MAX_OPTIONS ? 'gray.400' : '#1366C9'
}
borderColor={
localListItems.length >= MAX_OPTIONS ? 'gray.300' : '#1366C9'
}
borderWidth="2px"
fontSize="sm"
_hover={localListItems.length >= MAX_OPTIONS ? {} : { bg: '#1366C9', color: 'white' }}
_hover={
localListItems.length >= MAX_OPTIONS
? {}
: { bg: '#1366C9', color: 'white' }
}
_disabled={{ opacity: 1, cursor: 'not-allowed' }}
isDisabled={localListItems.length >= MAX_OPTIONS}
>
Expand All @@ -382,7 +413,12 @@ export const WhatsAppOptionsListSettingsBody = ({
</Stack>
<Stack>
<Flex>
<FormLabel mb="0" htmlFor="footer-input" fontWeight="bold" fontSize={'sm'}>
<FormLabel
mb="0"
htmlFor="footer-input"
fontWeight="bold"
fontSize={'sm'}
>
Texto do rodapé
</FormLabel>
<Spacer />
Expand Down
14 changes: 11 additions & 3 deletions apps/builder/components/shared/Graph/Nodes/helpers/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ const hasConditionSameTargetBlock = (step: Step, edges: Edge[]): boolean => {
if (validItems.length === 0) return false

const itemEdge = edges.find(
(e) => e.from.stepId === step.id && e.from.itemId && validItems.some((item) => item.id === e.from.itemId)
(e) =>
e.from.stepId === step.id &&
e.from.itemId &&
validItems.some((item) => item.id === e.from.itemId)
)

const stepEdge = edges.find(
Expand All @@ -66,15 +69,20 @@ const inpuStepsWithFallbackMessages = [
IntegrationStepType.EXTERNAL_EVENT,
]

export const getValidationMessages = (step: Step, edges?: Edge[]): Array<ValidationMessage> => {
export const getValidationMessages = (
step: Step,
edges?: Edge[]
): Array<ValidationMessage> => {
try {
const data = []

if (edges && hasConditionSameTargetBlock(step, edges)) {
return [
{
type: VALIDATION_MESSAGE_TYPE.WARNING,
message: ['A etapa de sucesso e erro não pode apontar para a mesma etapa'],
message: [
'A etapa de sucesso e erro não pode apontar para a mesma etapa',
],
},
]
}
Expand Down
Loading