Skip to content
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

fix: nomenclature in register page #212

Merged
merged 13 commits into from
Dec 4, 2023
27 changes: 9 additions & 18 deletions apps/app/components/LectureForm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export default function LectureForm({ id }) {
setEvents(response.data);
});
}, []);

useEffect(() => {
if (id !== "new") {
listEvents().then((response) => {
Expand All @@ -51,15 +52,15 @@ export default function LectureForm({ id }) {
}, []);

const [ninjas, setNinjas] = useState([]);
const fetchData = useCallback(() => {
let promise;

let promise;

const fetchData = () => {
if (!promise) {
promise = Promise.all(events.map((event) => getNinjaEvents(event.id)));
}

return promise;
};
}, [events]);

useEffect(() => {
fetchData().then((responses) => {
Expand All @@ -71,7 +72,7 @@ export default function LectureForm({ id }) {
)
);
});
}, [events]);
}, [fetchData]);

const [filteredNinjas, setFilteredNinjas] = useState([]);
const handleEventChange = useCallback(
Expand All @@ -94,7 +95,8 @@ export default function LectureForm({ id }) {
const filtered = mentors.filter((mentor) => {
const lecture = lectures.find(
(lecture) =>
lecture.mentor.id === mentor.id && lecture.event.id === selectedEvent
lecture.mentor.id === mentor.id &&
lecture.event.id === selectedEvent.id
);
return !lecture;
});
Expand All @@ -107,25 +109,14 @@ export default function LectureForm({ id }) {
);
}, [filteredNinjas]);

useEffect(() => {
const filtered = ninjas.filter((ninja) => {
const lecture = lectures.find(
(lecture) =>
lecture.ninja.id === ninja.id && lecture.event.id === selectedEvent
);
return !lecture;
});
setFilteredNinjas(filtered);
}, [ninjas, selectedEvent, lectures, handleEventChange]);

useEffect(() => {
setFilteredMentors(
filteredMentors.sort((a, b) => a.first_name.localeCompare(b.first_name))
);
}, [filteredMentors]);

const onFinish = (values) => {
if (Object.keys(selectedEvent).length != 0) {
if (Object.keys(selectedEvent).length !== 0) {
api
.createLecture(values)
.then(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
Form,
Input,
Radio,
Space,
Tooltip,
Typography,
} from "antd";
Expand All @@ -15,21 +16,19 @@ import {
MailOutlined,
} from "@ant-design/icons";
import { useAuth } from "@coderdojobraga/ui";
import Koi from "~/components/Koi";

import styles from "./style.module.css";

function Signup() {
const { Title, Text } = Typography;
const { errors, isLoading, sign_up } = useAuth();

const [size, setSize] = useState("");

const handleSizeChange = (e) => {
const handleSizeChange = (e: any) => {
setSize(e.target.value);
};

const onFinish = ({ email, password, role }) => {
const onFinish = ({ email, password, role }: any) => {
sign_up({ email, password, role });
};

Expand Down Expand Up @@ -73,26 +72,30 @@ function Signup() {
},
]}
>
<Radio.Group
className={styles.select}
value={size}
onChange={handleSizeChange}
>
<Radio.Button className={styles.option} value="guardian">
Guardião
</Radio.Button>
<Radio.Button className={styles.option} value="mentor">
Mentor
</Radio.Button>
<Tooltip
className={styles.option}
title="Inicia sessão como Guardião para inscreveres um Ninja"
>
<Radio.Button disabled>
Ninja &#160;
<InfoCircleOutlined />
</Radio.Button>
</Tooltip>
<Radio.Group value={size} onChange={handleSizeChange}>
<Space direction="vertical">
<Radio value="guardian" className="mb-2">
<span className="inline-block w-20">Guardião</span>
<label id="mentor-description" className="text-gray-500">
Tutor legal da criança.
</label>
</Radio>
<Radio value="mentor" className="mb-2">
<span className="inline-block w-20">Mentor</span>
<label id="mentor-description" className="text-gray-500">
Voluntário na organização.
</label>
</Radio>
<Tooltip title="Inicia sessão como Guardião para inscreveres um Ninja">
<Radio disabled value="1">
<span className="inline-block w-20">Ninja</span>
<label id="mentor-description" className=" text-gray-500">
Criança participante. &nbsp;
</label>
<InfoCircleOutlined />
</Radio>
</Tooltip>
</Space>
</Radio.Group>
</Form.Item>

Expand Down Expand Up @@ -124,7 +127,7 @@ function Signup() {
<Form.Item
className={styles.button}
validateStatus={errors && "error"}
help={errors?.email && "Email já registado"}
help={errors || "Email já registado"}
>
<Button
type="primary"
Expand Down
48 changes: 21 additions & 27 deletions apps/app/pages/admin/lectures/presences/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export default function Presences() {
const [selectedLectures, setSelectedLectures] = useState<Lecture[]>([]);
const [locations, setLocations] = useState<any[]>([]);
const router = useRouter();

const onFinish = (values: any, lectureId: string) => {
api
.updateLecture(lectureId, values)
Expand Down Expand Up @@ -98,7 +99,7 @@ export default function Presences() {
key: lecture.id,
});
});
}, []);
}, [selectedLectures, data]);

useEffect(() => {
api
Expand All @@ -111,36 +112,29 @@ export default function Presences() {
);
});
}, []);

useEffect(() => {
if (selectedEvent !== "") {
setSelectedLectures(
lectures.filter((lecture) => lecture.event.id === selectedEvent)
);
}
}, [selectedEvent, lectures]);
const generateData = () => {
const data: any[] = [];

useEffect(() => {
generateData();
}, [selectedLectures]);

const generateData = () => {
const data: any[] = [];

selectedLectures.map((lecture: any) => {
if (lecture.attendance == null) {
lecture.attendance = "both_absent";
}
data.push({
ninja: `${lecture.ninja.first_name} ${lecture.ninja.last_name}`,
mentor: `${lecture.mentor.first_name} ${lecture.mentor.last_name}`,
presences: `${lecture.attendance}`,
key: lecture.id,
selectedLectures.forEach((lecture: any) => {
if (lecture.attendance == null) {
lecture.attendance = "both_absent";
}
data.push({
ninja: `${lecture.ninja.first_name} ${lecture.ninja.last_name}`,
mentor: `${lecture.mentor.first_name} ${lecture.mentor.last_name}`,
presences: `${lecture.attendance}`,
key: lecture.id,
});
});
});

setData(data);
};
setData(data);
};

if (selectedLectures.length > 0) {
generateData();
}
}, [selectedLectures]);

const handleEditButtonClick = () => {
setEditButtonVisible(false);
Expand Down
4 changes: 4 additions & 0 deletions apps/web/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
NEXT_PUBLIC_API_URL=http://localhost:4000
WEB_URL=http://localhost:3000
BLOG_URL=http://localhost:3001
APP_URL=http://localhost:3002