Skip to content

Commit

Permalink
[#11] fix: initial cid setting
Browse files Browse the repository at this point in the history
  • Loading branch information
hee-suh committed May 22, 2022
1 parent 2b10d1e commit 805fec5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
26 changes: 17 additions & 9 deletions react-native/components/BottomDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,26 @@ const highlight = (text: string, registered: boolean) =>
function BottomDrawer(props: BottomDrawerProps) {
const [currentEvent, setCurrentEvent] = useState<number>(0);
const [openEventForm, setOpenEventForm] = useState<boolean>(false);
const [eventForm, setEventForm] = useState<EventForm>({cid: 1, title: '', date: '', description: ''});
const [eventForm, setEventForm] = useState<EventForm>({cid: 0, title: '', date: '', description: ''});
const [calendarAlert, setCalendarAlert] = useState<boolean>(false);
const [calendarUrl, setCalendarUrl] = useState<string>('');
const [resultsForm, setResultsForm] = useState<ResultsForm>({cid: 1, title: 'title'});
const [resultsForm, setResultsForm] = useState<ResultsForm>({cid: 0, title: 'title'});
const [user, setUser] = useState<UserData>();
const [firstCid, setFirstCid] = useState(0);
const auth = useAuth();
const navigation = useNavigation();
const cancelRef = React.useRef(null);

useEffect(()=> {
setUser(auth?.userData);
if (auth?.userData) {
setUser(auth?.userData);
if (auth?.userData?.uchildren && auth.userData.uchildren.length > 0) {
let cid = auth.userData.uchildren[0].cid
setEventForm({...eventForm, ['cid']: cid});
setResultsForm({...resultsForm, ['cid']: cid});
setFirstCid(cid);
}
}
}, [auth]);

useEffect(() => {
Expand All @@ -38,14 +47,15 @@ function BottomDrawer(props: BottomDrawerProps) {
}
});
if (event?.content && user?.uchildren) {
setEventForm({title: '['+user.uchildren[eventForm.cid-1]?.cname+'] ' + event.content, date: event?.date ? event.date : '', cid: eventForm.cid, description: eventForm.description });
let cname = user.uchildren.filter(child => child.cid === eventForm.cid)[0].cname;
setEventForm({title: '['+cname+'] ' + event.content, date: event?.date ? event.date : '', cid: eventForm.cid, description: eventForm.description });
}
}
}, [currentEvent, eventForm?.cid])

useEffect(() => {
if (props.openSaveForm) {
setResultsForm({ cid: 1, title: 'title' });
if (props.openSaveForm && firstCid) {
setResultsForm({ cid: firstCid, title: 'title' });
}
}, [props?.openSaveForm])

Expand All @@ -69,8 +79,6 @@ function BottomDrawer(props: BottomDrawerProps) {
}

const addEvent = () => {
handleCalendarAlert();

if (auth?.authData?.jwt_token && eventForm) {
console.log(eventForm, currentEvent);
fetch(`http://localhost:8080/event/register?id=${currentEvent}`, {
Expand All @@ -88,7 +96,7 @@ function BottomDrawer(props: BottomDrawerProps) {
if (data.url) {
setCalendarUrl(data.url) // console.log(data)
handleCalendarAlert();
auth?.handleUpdate();
// auth?.handleUpdate();
}
else {
Alert.alert(i18n.t('registerFailed'));
Expand Down
2 changes: 1 addition & 1 deletion react-native/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export type TextInput = {
}

interface Children {
cid?: number,
cid: number,
cname?: string,
color?: number,
}
Expand Down

0 comments on commit 805fec5

Please sign in to comment.