Skip to content

Commit

Permalink
DBC22-2802: payload integration
Browse files Browse the repository at this point in the history
  • Loading branch information
ray-oxd committed Jan 29, 2025
1 parent db30267 commit 7007681
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 10 deletions.
14 changes: 9 additions & 5 deletions src/backend/apps/authentication/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ class Meta:


class SavedRoutesSerializer(SafeStringMixin, serializers.ModelSerializer):

class Meta:
model = SavedRoutes
fields = ('id', 'label', 'distance', 'distance_unit',
'start', 'start_point', 'end', 'end_point',
'validated', 'thumbnail', 'route', 'criteria',
'searchTimestamp', 'notification')
fields = (
'id', 'label', 'distance', 'distance_unit',
'start', 'start_point', 'end', 'end_point',
'validated', 'thumbnail', 'route', 'criteria',
'searchTimestamp', 'notification', 'notification_types',
'notification_days', 'notification_start_date',
'notification_end_date', 'notification_start_time',
'notification_end_time',
)

def save(self):
''' Save the route with the requesting user. '''
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/Components/data/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export const patchRoute = async (route, selectedRoute, dispatch, body) => {
}

const savedRoute = await response.json();
const payload = {...route, notification: savedRoute.notification};
const payload = {...route, ...savedRoute};
if (selectedRoute && selectedRoute.id === route.id) {
dispatch(updateSelectedRoute(payload));
}
Expand Down
18 changes: 14 additions & 4 deletions src/frontend/src/Components/routing/RouteDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,10 +388,20 @@ export default function RouteDetails(props) {
return;
}

// const body = { notification: true };
// const response = await patchRoute(route, selectedRoute, dispatch, body);
// setNotificationsEnabled(response.notification);
// setShowNotificationForm(false);
const defaultPayload = { notification: true };
const eventTypePayload = EventTypeFormRef.current.getPayload();
const dateTimePayload = DateTimeFormRef.current.getPayload();
const payload = {
...defaultPayload,
...eventTypePayload,
...dateTimePayload
};

console.log('payload', payload);

const response = await patchRoute(route, selectedRoute, dispatch, payload);
setNotificationsEnabled(response.notification);
setShowNotificationForm(false);
}

// Main components
Expand Down
35 changes: 35 additions & 0 deletions src/frontend/src/Components/routing/forms/NotificationDateTime.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,41 @@ const NotificationDateTime = forwardRef((props, ref) => {

setErrorMessages(errors);
return errors.length === 0;
},

getPayload() {
const payload = {
notification_days: [],
notification_start_date: null,
notification_end_date: null,
notification_start_time: null,
notification_end_time: null
}

// Send immediately and all the time
if (!showSpecificTimeDate) {
return payload;
}

// Time range for all date/day options
payload.notification_start_time = startTime;
payload.notification_end_time = endTime;

// Specific date
if (specificDateOption === 'Specific date') {
payload.notification_start_date = startDate;

// Date range
} else if (specificDateOption === 'Date range') {
payload.notification_start_date = startDate;
payload.notification_end_date = endDate;

// Days of the week
} else {
payload.notification_days = Object.keys(dayOfWeek).filter(day => dayOfWeek[day]);
}

return payload;
}
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ const NotificationEventType = forwardRef((props, ref) => {
setErrorMessage('');
}
return isValid;
},

getPayload() {
return {
notification_types: Object.keys(notificationEventTypes).filter(type => notificationEventTypes[type])
};
}
}));

Expand Down

0 comments on commit 7007681

Please sign in to comment.