From 3757072d8241a6997036d2fe4f6e77248907486f Mon Sep 17 00:00:00 2001 From: Pedro Gomes Date: Thu, 1 Aug 2024 02:40:16 -0300 Subject: [PATCH] Screen Finished Visit --- src/components/Overview/styles.ts | 1 - src/components/QuestionSection/index.tsx | 50 +++++++++++-------- .../EvaluateVisitManager/index.tsx | 1 - src/screens/EvaluateVisit/index.tsx | 17 ++++--- 4 files changed, 41 insertions(+), 28 deletions(-) diff --git a/src/components/Overview/styles.ts b/src/components/Overview/styles.ts index 5e23679..155ba46 100644 --- a/src/components/Overview/styles.ts +++ b/src/components/Overview/styles.ts @@ -57,7 +57,6 @@ export const NoVisitsContainer = styled(View)` height: 15%; display: flex; - background-color: red; align-items: 'center'; justify-content: 'center'; `; diff --git a/src/components/QuestionSection/index.tsx b/src/components/QuestionSection/index.tsx index d8e9351..ece781a 100644 --- a/src/components/QuestionSection/index.tsx +++ b/src/components/QuestionSection/index.tsx @@ -29,7 +29,6 @@ interface Props { onUpdateAnswers: (answers: any[]) => void; onCategoryUpdate?: (updatedCategory: ICategories) => void; onDeleteCategory?: (categoryId: string) => void; // Novo prop para deletar categoria - loading?: boolean; } const QuestionSection: React.FC = ({ @@ -40,7 +39,6 @@ const QuestionSection: React.FC = ({ onUpdateAnswers, onCategoryUpdate, onDeleteCategory, - loading, }) => { const [categoryQuestions, setCategoryQuestions] = useState([]); const [answers, setAnswers] = useState([]); @@ -52,10 +50,12 @@ const QuestionSection: React.FC = ({ const [isDeleting, setIsDeleting] = useState(false); // Novo estado de carregamento const { user } = useAuth(); const toast = useToast(); + const [loading, setLoading] = useState(false); useEffect(() => { const fetchQuestions = async () => { try { + setLoading(true); const questions = await VisitService.getQuestionsByIdCategory( category.id ); @@ -63,6 +63,8 @@ const QuestionSection: React.FC = ({ setEditedQuestions(questions); } catch (error) { console.log(error); + } finally { + setLoading(false); } }; fetchQuestions(); @@ -114,7 +116,7 @@ const QuestionSection: React.FC = ({ for (const question of editedQuestions) { await VisitService.updateQuestion({ - id: question.id, + id: question.id || '', question: question.question, }); } @@ -135,11 +137,13 @@ const QuestionSection: React.FC = ({ setEditedCategory({ ...editedCategory, name }); }; - const handleQuestionChange = (id: string, question: string) => { - const updatedQuestions = editedQuestions.map((q) => - q.id === id ? { ...q, question } : q - ); - setEditedQuestions(updatedQuestions); + const handleQuestionChange = (id: string | undefined, question: string) => { + if (id) { + const updatedQuestions = editedQuestions.map((q) => + q.id === id ? { ...q, question } : q + ); + setEditedQuestions(updatedQuestions); + } }; const showToast = (message: string, type: string) => { @@ -249,12 +253,14 @@ const QuestionSection: React.FC = ({ handleQuestionChange(question.id, text)} + onChangeText={(text) => + handleQuestionChange(question.id!, text) + } placeholder="Edit Question" placeholderTextColor="#666" /> handleDeleteQuestion(question.id)} + onPress={() => handleDeleteQuestion(question.id!)} > = ({ ) : ( <> {category?.name || 'Tema Question'} - {categoryQuestions.map((question, index) => ( - - - handleInputChange(question.id, value, question.question) - } - textAsk={question.question} - /> - - ))} + {loading ? ( + + ) : ( + categoryQuestions.map((question, index) => ( + + + handleInputChange(question.id!, value, question.question) + } + textAsk={question.question} + /> + + )) + )} )} diff --git a/src/screens/EvaluateVisit/EvaluateVisitManager/index.tsx b/src/screens/EvaluateVisit/EvaluateVisitManager/index.tsx index bfd1413..1ebb664 100644 --- a/src/screens/EvaluateVisit/EvaluateVisitManager/index.tsx +++ b/src/screens/EvaluateVisit/EvaluateVisitManager/index.tsx @@ -290,7 +290,6 @@ const EvaluateVisitManager = () => { { setIndexScreen(1); setSelectedSeller(null); setStoreName(''); + setCategories([]); }; return ( @@ -304,12 +305,16 @@ const EvaluateVisit = () => { {indexScreen === categories.length && categories.length !== 0 && ( <> - setIndexScreen(indexScreen + 1)}> - Ver Resumo do dia de visita - - - Iniciar nova visita - + + setIndexScreen(indexScreen + 1)} + > + Ver Resumo do dia de visita + + + Iniciar nova visita + + )}