Skip to content

Commit

Permalink
feat: add register chapter page
Browse files Browse the repository at this point in the history
  • Loading branch information
davigps committed Apr 10, 2024
1 parent f42c4d2 commit a96f8d1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 14 deletions.
18 changes: 15 additions & 3 deletions app/courses/(private)/[courseId]/(only-teachers)/details.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import Feather from '@expo/vector-icons/Feather';
import { Redirect, useLocalSearchParams } from 'expo-router';
import { Redirect, useLocalSearchParams, useRouter } from 'expo-router';
import { StatusBar } from 'expo-status-bar';
import { useEffect, useState } from 'react';
import styled, { useTheme } from 'styled-components/native';

import { CourseView } from '@/api';
import BackButton from '@/components/BackButton';
import Button from '@/components/Button';
import Loading from '@/components/Loading';
import ScrollablePage from '@/components/ScrollablePage';
import Text from '@/components/Text';
import { CourseAccordion, NextContent } from '@/components/pages/courses';
import { CourseAccordion } from '@/components/pages/courses';
import {
ContentBackground,
DescriptionWrapper,
Expand All @@ -26,6 +27,7 @@ import { horizontalScale, verticalScale } from '@/utils/scale';
export default function ShowCourseDetails() {
const theme = useTheme();
const auth = useAuth();
const router = useRouter();
const { courseId } = useLocalSearchParams();

const [course, setCourse] = useState<CourseView | null>(null);
Expand Down Expand Up @@ -114,7 +116,17 @@ export default function ShowCourseDetails() {
{course.description}
</Text>

<NextContent course={course} />
<Button
onPress={() => router.push(`/courses/${courseId}/new-chapter`)}
style={{ marginTop: verticalScale(20) }}
color="secondary"
>
<Feather name="plus" size={24} color={theme.colors.light} />

<Text color="light" size="h6">
Cadastrar capítulo
</Text>
</Button>

<CourseAccordion course={course} />
</ContentContainer>
Expand Down
34 changes: 24 additions & 10 deletions app/courses/(private)/[courseId]/(only-teachers)/new-chapter.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Feather from '@expo/vector-icons/Feather';
import { router } from 'expo-router';
import FormData from 'form-data';
import { useLocalSearchParams, useRouter } from 'expo-router';
import { useState } from 'react';

import BackButton from '@/components/BackButton';
Expand All @@ -16,9 +15,14 @@ import {
NewCourseContainer,
TransparentBackground,
} from '@/components/pages/courses/styles';
import { client } from '@/services/client';
import { showErrors } from '@/services/errors';
import { showMessage } from '@/services/messages';

export default function NewCourse() {
const router = useRouter();
const { courseId } = useLocalSearchParams();

const [title, setTitle] = useState('');
const [loading, setLoading] = useState(false);

Expand All @@ -35,14 +39,24 @@ export default function NewCourse() {

setLoading(true);

const formData = new FormData();
formData.append('name', title);
showMessage({
type: 'success',
title: 'Sucesso!',
message: 'Conteúdo cadastrado com sucesso!',
});
router.replace('/courses/1/new-chapter');
try {
await client.courseChapters.createCourseChapterCourseChapterPost({
course_id: Number(courseId),
name: title,
});

showMessage({
type: 'success',
title: 'Sucesso!',
message: 'Capítulo cadastrado com sucesso!',
});

router.replace(`/courses/${courseId}/details`);
} catch (error) {
showErrors(error);
} finally {
setLoading(false);
}
};

return (
Expand Down
2 changes: 1 addition & 1 deletion components/pages/courses/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function CourseSummary({
<CourseViewWrapper onPress={onPress} isInProgress={isInProgress}>
<CourseViewBackground
defaultSource={require('assets/gray.png')}
source={{ uri: course.image_url }}
source={{ uri: course.image_url || '' }}
resizeMode="cover"
imageStyle={{ borderRadius: moderateScale(25), width: '100%' }}
>
Expand Down

0 comments on commit a96f8d1

Please sign in to comment.