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

add check on event creation #67

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/modules/createEvent/CreateEvent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,27 @@ const CreateEvent = ({ navigation, route }: CreateEventProps) => {

const schema = data['eventSchemas'][route.params.type.toLowerCase()];

function hasAllEventDetails(eventData: any) {
return (

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this works quite right since different event types have different fields. For example, Special Events don't have a distance field, so with this logic it's impossible to create one. There's probably some way to check all of the fields specific to the event type?

eventData.date &&
eventData.description &&
eventData.distance &&
eventData.endTime &&
eventData.location &&
eventData.startTime &&
eventData.title &&
eventData.uniqueMeetLocation
);
}

const createEvent = () => {
const eventDataCopy = { ...fields };

if (!hasAllEventDetails(eventDataCopy)) {
alert('missing required event details');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use the Toast component for all error messages, just replace alert with something like

Toast.show('Missing required event details', {
      duration: Toast.durations.LONG,
      backgroundColor: 'red',
      position: 20,
});

(plus the import ofc)

return;
}

if (route.params.update) {
const omitInvalidFields = (key, value) => {
if (key === '__typename') {
Expand Down Expand Up @@ -155,7 +174,8 @@ const CreateEvent = ({ navigation, route }: CreateEventProps) => {
back={() => {
dispatch && dispatch(clearEventForm());
navigation.goBack();
}}>
}}
>
{/* Schema representing all the types of events currently in the app. This
comes from the server
TODO: gql form schema rewrite: update with the new form types */}
Expand Down