Skip to content

Commit

Permalink
Remove issueServerAction(), migrate remaining users to callApi()
Browse files Browse the repository at this point in the history
  • Loading branch information
beverloo committed Jan 26, 2024
1 parent 2a5e86b commit b9cac25
Show file tree
Hide file tree
Showing 29 changed files with 236 additions and 266 deletions.
18 changes: 8 additions & 10 deletions app/admin/events/EventCreate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ import Alert from '@mui/material/Alert';
import Paper from '@mui/material/Paper';
import Typography from '@mui/material/Typography';

import type { CreateEventDefinition } from '@app/api/admin/createEvent';
import { EventSettingsForm } from './[slug]/settings/EventSettingsForm';
import { SubmitCollapse } from '../components/SubmitCollapse';
import { issueServerAction } from '@lib/issueServerAction';
import { dayjs } from '@lib/DateTime';
import { callApi } from '@lib/callApi';

/**
* The <EventCreate> component enables certain volunteers to create new events on the fly. While
Expand All @@ -34,14 +33,13 @@ export function EventCreate() {
setError(undefined);
setLoading(true);
try {
const response = await issueServerAction<CreateEventDefinition>(
'/api/admin/create-event', {
name: data.name,
shortName: data.shortName,
slug: data.slug,
startTime: dayjs(data.startTime).utc().toISOString(),
endTime: dayjs(data.endTime).utc().toISOString(),
});
const response = await callApi('post', '/api/admin/create-event', {
name: data.name,
shortName: data.shortName,
slug: data.slug,
startTime: dayjs(data.startTime).utc().toISOString(),
endTime: dayjs(data.endTime).utc().toISOString(),
});

setError(response.error);
if (response.slug)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ import Typography from '@mui/material/Typography';

import type { PageInfoWithTeam } from '@app/admin/events/verifyAccessAndFetchPageInfo';
import type { User } from '@lib/auth/User';
import type { VolunteerListDefinition } from '@app/api/admin/volunteerList';
import { ApplicationAvailabilityForm, ApplicationParticipationForm }
from '@app/registration/[slug]/application/ApplicationParticipation';
import { callApi } from '@lib/callApi';
import { issueServerAction } from '@lib/issueServerAction';

/**
* Props accepted by the <VolunteerAutocompleteTextField> component.
Expand Down Expand Up @@ -69,7 +67,7 @@ function VolunteerAutocompleteTextField(props: VolunteerAutocompleteTextFieldPro

setFetching(true);

issueServerAction<VolunteerListDefinition>('/api/admin/volunteer-list', {
callApi('post', '/api/admin/volunteer-list', {
excludeEventId
}).then(({ volunteers }) => {
const removeDuplicateMap = new Map<string, number>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import { ContrastBox } from '@app/admin/components/ContrastBox';
import { Privilege, can } from '@lib/auth/Privileges';
import { RegistrationStatus } from '@lib/database/Types';
import { SettingDialog } from '@app/admin/components/SettingDialog';
import { issueServerAction } from '@lib/issueServerAction';
import { callApi } from '@lib/callApi';

type TeamsForVolunteer = VolunteerTeamsDefinition['response']['teams'];
Expand Down Expand Up @@ -94,13 +93,12 @@ function ChangeRoleDialog(props: ChangeRoleDialogProps) {

const handleChange = useCallback((value: any) => setSelectedRole(value), [ setSelectedRole ]);
const handleSubmit = useCallback(async (data: FieldValues) => {
const response = await issueServerAction<VolunteerRolesDefinition>(
'/api/admin/volunteer-roles', {
eventId,
roleId: data.role,
teamId,
userId: volunteer.userId,
});
const response = await callApi('post', '/api/admin/volunteer-roles', {
eventId,
roleId: data.role,
teamId,
userId: volunteer.userId,
});

if (response.success)
return { success: `${volunteer.firstName}'s role has been successfully updated.` };
Expand Down Expand Up @@ -450,10 +448,9 @@ export function VolunteerHeader(props: VolunteerHeaderProps) {
if (!roles) {
setRolesLoading(true);
try {
const response = await issueServerAction<VolunteerRolesDefinition>(
'/api/admin/volunteer-roles', {
teamId: team.id,
});
const response = await callApi('post', '/api/admin/volunteer-roles', {
teamId: team.id,
});

setRoles(response.roles);
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ import Typography from '@mui/material/Typography';
import WarningAmberIcon from '@mui/icons-material/WarningAmber';

import { RegistrationStatus } from '@lib/database/Types';
import type { VolunteerContactInfoDefinition } from '@app/api/admin/volunteerContactInfo';
import { Avatar } from '@components/Avatar';
import { callApi } from '@lib/callApi';
import { issueServerAction } from '@lib/issueServerAction';

/**
* Displays a loading skeleton to inform the user that contact information has not been loaded yet.
Expand Down Expand Up @@ -125,11 +123,11 @@ export function VolunteerIdentity(props: VolunteerIdentityProps) {
return; // contact information hasn't been requested

setContactInfoLoading(true);
issueServerAction<VolunteerContactInfoDefinition>(
'/api/admin/volunteer-contact-info', { event, teamId, userId }).then(response =>
{
setContactInfo(response);
});
callApi('post', '/api/admin/volunteer-contact-info', { event, teamId, userId }).then(
response =>
{
setContactInfo(response);
});

}, [ contactInfo, contactInfoLoading, emailAnchorEl, event, phoneNumberAnchorEl, teamId,
userId ])
Expand Down
19 changes: 8 additions & 11 deletions app/admin/events/[slug]/hotels/HotelConfiguration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ import type { GridRenderCellParams, GridValidRowModel } from '@mui/x-data-grid';
import Paper from '@mui/material/Paper';
import Typography from '@mui/material/Typography';

import type { HotelDefinition } from '@app/api/admin/hotel';
import type { PageInfo } from '@app/admin/events/verifyAccessAndFetchPageInfo';
import type { UpdatePublicationDefinition } from '@app/api/admin/updatePublication';
import { type DataTableColumn, OLD_DataTable } from '@app/admin/DataTable';
import { PublishAlert } from '@app/admin/components/PublishAlert';
import { issueServerAction } from '@lib/issueServerAction';
import { callApi } from '@lib/callApi';

/**
* Helper function for formatting prices in the configuration data table.
Expand Down Expand Up @@ -80,7 +78,7 @@ export function HotelConfiguration(props: HotelConfigurationProps) {
const { event } = props;

async function commitAdd(): Promise<HotelConfigurationEntry> {
const response = await issueServerAction<HotelDefinition>('/api/admin/hotel', {
const response = await callApi('post', '/api/admin/hotel', {
event: event.slug,
create: { /* empty payload */ }
});
Expand All @@ -99,7 +97,7 @@ export function HotelConfiguration(props: HotelConfigurationProps) {
}

async function commitDelete(oldRow: GridValidRowModel) {
await issueServerAction<HotelDefinition>('/api/admin/hotel', {
await callApi('post', '/api/admin/hotel', {
event: event.slug,
delete: {
id: oldRow.id,
Expand All @@ -108,7 +106,7 @@ export function HotelConfiguration(props: HotelConfigurationProps) {
}

async function commitEdit(newRow: GridValidRowModel, oldRow: GridValidRowModel) {
const response = await issueServerAction<HotelDefinition>('/api/admin/hotel', {
const response = await callApi('post', '/api/admin/hotel', {
event: event.slug,
update: {
id: oldRow.id,
Expand All @@ -126,11 +124,10 @@ export function HotelConfiguration(props: HotelConfigurationProps) {
const router = useRouter();

const onPublish = useCallback(async (domEvent: unknown, publish: boolean) => {
const response = await issueServerAction<UpdatePublicationDefinition>(
'/api/admin/update-publication', {
event: event.slug,
publishHotels: !!publish,
});
const response = await callApi('post', '/api/admin/update-publication', {
event: event.slug,
publishHotels: !!publish,
});

if (response.success)
router.refresh();
Expand Down
29 changes: 12 additions & 17 deletions app/admin/events/[slug]/refunds/RefundsHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ import Grid from '@mui/material/Unstable_Grid2';
import Paper from '@mui/material/Paper';

import type { PageInfo } from '@app/admin/events/verifyAccessAndFetchPageInfo';
import type { UpdateEventDefinition } from '@app/api/admin/updateEvent';
import type { UpdatePublicationDefinition } from '@app/api/admin/updatePublication';
import { PaperHeader } from '@app/admin/components/PaperHeader';
import { PublishAlert } from '@app/admin/components/PublishAlert';
import { SubmitCollapse } from '@app/admin/components/SubmitCollapse';
import { issueServerAction } from '@lib/issueServerAction';
import { callApi } from '@lib/callApi';
import { dayjs } from '@lib/DateTime';

/**
Expand Down Expand Up @@ -65,15 +63,13 @@ export function RefundsHeader(props: RefundsHeaderProps) {
data.refundsEndTime ? dayjs(data.refundsEndTime).utc().toISOString()
: undefined;

const response = await issueServerAction<UpdateEventDefinition>(
'/api/admin/update-event',
{
event: event.slug,
eventRefunds: {
refundsStartTime,
refundsEndTime,
},
});
const response = await callApi('post', '/api/admin/update-event', {
event: event.slug,
eventRefunds: {
refundsStartTime,
refundsEndTime,
},
});

if (response.success) {
setInvalidated(false);
Expand All @@ -90,11 +86,10 @@ export function RefundsHeader(props: RefundsHeaderProps) {
const [ published, setPublished ] = useState<boolean>(event.publishRefunds);

const handleRefundPublicationChange = useCallback(async () => {
const response = await issueServerAction<UpdatePublicationDefinition>(
'/api/admin/update-publication', {
event: event.slug,
publishRefunds: !published,
});
const response = await callApi('post', '/api/admin/update-publication', {
event: event.slug,
publishRefunds: !published,
});

if (response.success) {
setPublished(published => !published);
Expand Down
33 changes: 15 additions & 18 deletions app/admin/events/[slug]/settings/EventSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ import Paper from '@mui/material/Paper';
import Typography from '@mui/material/Typography';

import type { PageInfo } from '@app/admin/events/verifyAccessAndFetchPageInfo';
import type { UpdateEventDefinition } from '@app/api/admin/updateEvent';
import { EventAvailabilityStatus } from '@lib/database/Types';
import { EventSettingsForm } from './EventSettingsForm';
import { SubmitCollapse } from '@app/admin/components/SubmitCollapse';
import { issueServerAction } from '@lib/issueServerAction';
import { callApi } from '@lib/callApi';
import { dayjs } from '@lib/DateTime';

/**
Expand Down Expand Up @@ -66,22 +65,20 @@ export function EventSettings(props: EventSettingsProps) {
const handleSubmit = useCallback(async (data: FieldValues) => {
setLoading(true);
try {
const response = await issueServerAction<UpdateEventDefinition>(
'/api/admin/update-event',
{
event: event.slug,
eventSettings: {
name: data.name,
shortName: data.shortName,
timezone: data.timezone,
startTime: dayjs(data.startTime).utc().toISOString(),
endTime: dayjs(data.endTime).utc().toISOString(),
availabilityStatus: data.availabilityStatus,
location: data.location,
festivalId: data.festivalId,
hotelRoomForm: data.hotelRoomForm,
},
});
const response = await callApi('post', '/api/admin/update-event', {
event: event.slug,
eventSettings: {
name: data.name,
shortName: data.shortName,
timezone: data.timezone,
startTime: dayjs(data.startTime).utc().toISOString(),
endTime: dayjs(data.endTime).utc().toISOString(),
availabilityStatus: data.availabilityStatus,
location: data.location,
festivalId: data.festivalId,
hotelRoomForm: data.hotelRoomForm,
},
});

if (response.success) {
setInvalidated(false);
Expand Down
11 changes: 5 additions & 6 deletions app/admin/events/[slug]/settings/SettingsHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ import StopCircleIcon from '@mui/icons-material/StopCircle';
import Typography from '@mui/material/Typography';

import type { PageInfo } from '@app/admin/events/verifyAccessAndFetchPageInfo';
import type { UpdateEventDefinition } from '@app/api/admin/updateEvent';
import { ContrastBox } from '@app/admin/components/ContrastBox';
import { LazyAvatarEditor } from '@components/LazyAvatarEditor';
import { SettingDialog } from '@app/admin/components/SettingDialog';
import { TransitionAlert } from '@app/admin/components/TransitionAlert';
import { issueServerAction } from '@lib/issueServerAction';
import { callApi } from '@lib/callApi';

/**
* Description to use for the event publication dialog.
Expand Down Expand Up @@ -86,7 +85,7 @@ export function SettingsHeader(props: SettingsHeaderProps) {

const openPublish = useCallback(() => setPublishOpen(true), [ /* no deps */ ]);
const handlePublish = useCallback(async () => {
const response = await issueServerAction<UpdateEventDefinition>('/api/admin/update-event', {
const response = await callApi('post', '/api/admin/update-event', {
event: event.slug,
eventHidden: /* publish= */ false,
});
Expand All @@ -97,7 +96,7 @@ export function SettingsHeader(props: SettingsHeaderProps) {

const openSuspend = useCallback(() => setSuspendOpen(true), [ /* no deps */ ]);
const handleSuspend = useCallback(async () => {
const response = await issueServerAction<UpdateEventDefinition>('/api/admin/update-event', {
const response = await callApi('post', '/api/admin/update-event', {
event: event.slug,
eventHidden: /* suspend= */ true,
});
Expand All @@ -118,7 +117,7 @@ export function SettingsHeader(props: SettingsHeaderProps) {
reader.readAsDataURL(avatar);
});

const response = await issueServerAction<UpdateEventDefinition>('/api/admin/update-event', {
const response = await callApi('post', '/api/admin/update-event', {
event: event.slug,
eventIdentity: base64Avatar as string,
});
Expand All @@ -133,7 +132,7 @@ export function SettingsHeader(props: SettingsHeaderProps) {

const openSlug = useCallback(() => setSlugOpen(true), [ /* no deps */ ]);
const handleSlug = useCallback(async (data: any) => {
const response = await issueServerAction<UpdateEventDefinition>('/api/admin/update-event', {
const response = await callApi('post', '/api/admin/update-event', {
event: event.slug,
eventSlug: data.slug,
});
Expand Down
5 changes: 2 additions & 3 deletions app/admin/events/[slug]/settings/TeamSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ import Typography from '@mui/material/Typography';

import type { DataTableColumn } from '@app/admin/DataTable';
import type { PageInfo } from '@app/admin/events/verifyAccessAndFetchPageInfo';
import type { UpdateEventDefinition } from '@app/api/admin/updateEvent';
import { OLD_DataTable } from '@app/admin/DataTable';
import { issueServerAction } from '@lib/issueServerAction';
import { callApi } from '@lib/callApi';

/**
* Settings related to an individual team whose settings can be updated on this page.
Expand Down Expand Up @@ -175,7 +174,7 @@ export function TeamSettings(props: TeamSettingsProps) {
const router = useRouter();

const handleEdit = useCallback(async (newRow: GridValidRowModel, oldRow: GridValidRowModel) => {
const response = await issueServerAction<UpdateEventDefinition>('/api/admin/update-event', {
const response = await callApi('post', '/api/admin/update-event', {
event: event.slug,
team: {
id: oldRow.id,
Expand Down
12 changes: 5 additions & 7 deletions app/admin/events/[slug]/training/TrainingConfiguration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import Typography from '@mui/material/Typography';

import type { PageInfo } from '@app/admin/events/verifyAccessAndFetchPageInfo';
import type { TrainingsRowModel } from '@app/api/admin/trainings/[[...id]]/route';
import type { UpdatePublicationDefinition } from '@app/api/admin/updatePublication';
import { PublishAlert } from '@app/admin/components/PublishAlert';
import { RemoteDataTable, type RemoteDataTableColumn } from '@app/admin/components/RemoteDataTable';
import { callApi } from '@lib/callApi';
import { dayjs, fromLocalDate, toLocalDate } from '@lib/DateTime';
import { issueServerAction } from '@lib/issueServerAction';

/**
* Props accepted by the <TrainingConfiguration> component.
Expand All @@ -37,11 +36,10 @@ export function TrainingConfiguration(props: TrainingConfigurationProps) {
const router = useRouter();

const onPublish = useCallback(async (domEvent: unknown, publish: boolean) => {
const response = await issueServerAction<UpdatePublicationDefinition>(
'/api/admin/update-publication', {
event: event.slug,
publishTrainings: !!publish,
});
const response = await callApi('post', '/api/admin/update-publication', {
event: event.slug,
publishTrainings: !!publish,
});

if (response.success)
router.refresh();
Expand Down
Loading

0 comments on commit b9cac25

Please sign in to comment.