Skip to content

Commit

Permalink
Screen Finished Visit
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrogomes18 committed Aug 1, 2024
1 parent 4499a54 commit 3757072
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 28 deletions.
1 change: 0 additions & 1 deletion src/components/Overview/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ export const NoVisitsContainer = styled(View)`
height: 15%;
display: flex;
background-color: red;
align-items: 'center';
justify-content: 'center';
`;
Expand Down
50 changes: 30 additions & 20 deletions src/components/QuestionSection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<Props> = ({
Expand All @@ -40,7 +39,6 @@ const QuestionSection: React.FC<Props> = ({
onUpdateAnswers,
onCategoryUpdate,
onDeleteCategory,
loading,
}) => {
const [categoryQuestions, setCategoryQuestions] = useState<IQuestions[]>([]);
const [answers, setAnswers] = useState<any[]>([]);
Expand All @@ -52,17 +50,21 @@ const QuestionSection: React.FC<Props> = ({
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
);
setCategoryQuestions(questions);
setEditedQuestions(questions);
} catch (error) {
console.log(error);
} finally {
setLoading(false);
}
};
fetchQuestions();
Expand Down Expand Up @@ -114,7 +116,7 @@ const QuestionSection: React.FC<Props> = ({

for (const question of editedQuestions) {
await VisitService.updateQuestion({
id: question.id,
id: question.id || '',
question: question.question,
});
}
Expand All @@ -135,11 +137,13 @@ const QuestionSection: React.FC<Props> = ({
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) => {
Expand Down Expand Up @@ -249,12 +253,14 @@ const QuestionSection: React.FC<Props> = ({
<TextInput
style={styles.questionInput}
value={question.question}
onChangeText={(text) => handleQuestionChange(question.id, text)}
onChangeText={(text) =>
handleQuestionChange(question.id!, text)
}
placeholder="Edit Question"
placeholderTextColor="#666"
/>
<TouchableOpacity
onPress={() => handleDeleteQuestion(question.id)}
onPress={() => handleDeleteQuestion(question.id!)}
>
<FontAwesome
name="trash"
Expand Down Expand Up @@ -312,16 +318,20 @@ const QuestionSection: React.FC<Props> = ({
) : (
<>
<S.TemaQuestion>{category?.name || 'Tema Question'}</S.TemaQuestion>
{categoryQuestions.map((question, index) => (
<S.Wrapper key={question.id}>
<InputRange
onChangeValue={(id: string, value: number) =>
handleInputChange(question.id, value, question.question)
}
textAsk={question.question}
/>
</S.Wrapper>
))}
{loading ? (
<ActivityIndicator size="large" color="#3E63DD" />
) : (
categoryQuestions.map((question, index) => (
<S.Wrapper key={question.id}>
<InputRange
onChangeValue={(id: string, value: number) =>
handleInputChange(question.id!, value, question.question)
}
textAsk={question.question}
/>
</S.Wrapper>
))
)}
</>
)}
</ScrollView>
Expand Down
1 change: 0 additions & 1 deletion src/screens/EvaluateVisit/EvaluateVisitManager/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ const EvaluateVisitManager = () => {
<S.CategoryContainer key={category.id}>
<QuestionSection
key={category.id}
loading={loading}
sellerId=""
category={category}
index={idx + 1}
Expand Down
17 changes: 11 additions & 6 deletions src/screens/EvaluateVisit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ const EvaluateVisit = () => {
setIndexScreen(1);
setSelectedSeller(null);
setStoreName('');
setCategories([]);
};

return (
Expand Down Expand Up @@ -304,12 +305,16 @@ const EvaluateVisit = () => {

{indexScreen === categories.length && categories.length !== 0 && (
<>
<S.ButtonIniciar onPress={() => setIndexScreen(indexScreen + 1)}>
<S.TextBtn>Ver Resumo do dia de visita</S.TextBtn>
</S.ButtonIniciar>
<S.Outline onPress={initialNewVisit}>
<S.TextBtnNova>Iniciar nova visita</S.TextBtnNova>
</S.Outline>
<S.ContainerButton>
<S.ButtonIniciar
onPress={() => setIndexScreen(indexScreen + 1)}
>
<S.TextBtn>Ver Resumo do dia de visita</S.TextBtn>
</S.ButtonIniciar>
<S.Outline onPress={initialNewVisit}>
<S.TextBtnNova>Iniciar nova visita</S.TextBtnNova>
</S.Outline>
</S.ContainerButton>
</>
)}

Expand Down

0 comments on commit 3757072

Please sign in to comment.