Skip to content

Commit

Permalink
Remove redux-first-history
Browse files Browse the repository at this point in the history
It is not compatible with `react-router` v6.4, and is not something we
"really" need.
  • Loading branch information
ivarnakken committed Dec 24, 2023
1 parent 67884c2 commit e092e4c
Show file tree
Hide file tree
Showing 34 changed files with 257 additions and 315 deletions.
6 changes: 2 additions & 4 deletions app/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,17 @@ import ErrorBoundary from 'app/components/ErrorBoundary';
import { ThemeContextListener } from 'app/utils/themeUtils';
import RouteConfig from './routes';
import type { Store } from 'app/store/createStore';
import type { History } from 'history';

type Props = {
store: Store;
connectedHistory: History & { listenObject: boolean };
};

const Root = ({ store, connectedHistory }: Props) => (
const Root = ({ store }: Props) => (
<HelmetProvider>
<Provider store={store}>
<ThemeContextListener />
<ErrorBoundary openReportDialog>
<Router history={connectedHistory}>
<Router>
<CompatRouter>
<RouteConfig />
</CompatRouter>
Expand Down
52 changes: 20 additions & 32 deletions app/actions/ArticleActions.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { omit } from 'lodash';
import { push } from 'redux-first-history';
import callAPI from 'app/actions/callAPI';
import { articleSchema } from 'app/reducers';
import { Article } from './ActionTypes';
import type { AppDispatch } from 'app/store/createStore';
import type { ID } from 'app/store/models';
import type { DetailedArticle } from 'app/store/models/Article';
import type { ArticleEntity } from 'app/types';
Expand All @@ -21,23 +19,16 @@ export function fetchArticle(articleId: ID) {
}

export function createArticle(data: ArticleEntity) {
return (dispatch: AppDispatch) =>
dispatch(
callAPI<DetailedArticle>({
types: Article.CREATE,
endpoint: '/articles/',
method: 'POST',
schema: articleSchema,
body: omit(data, ['id']),
meta: {
errorMessage: 'Opprettelse av artikkel feilet',
},
})
).then(
(action) =>
'success' in action &&
dispatch(push(`/articles/${action.payload.result}/`))
);
return callAPI<DetailedArticle>({
types: Article.CREATE,
endpoint: '/articles/',
method: 'POST',
schema: articleSchema,
body: omit(data, ['id']),
meta: {
errorMessage: 'Opprettelse av artikkel feilet',
},
});
}

export function deleteArticle(id: ID) {
Expand All @@ -53,19 +44,16 @@ export function deleteArticle(id: ID) {
}

export function editArticle({ id, ...data }: ArticleEntity) {
return (dispatch: AppDispatch) =>
dispatch(
callAPI({
types: Article.EDIT,
endpoint: `/articles/${id}/`,
method: 'PUT',
schema: articleSchema,
body: data,
meta: {
errorMessage: 'Endring av artikkel feilet',
},
})
).then(() => dispatch(push(`/articles/${id}/`)));
return callAPI<DetailedArticle>({
types: Article.EDIT,
endpoint: `/articles/${id}/`,
method: 'PUT',
schema: articleSchema,
body: data,
meta: {
errorMessage: 'Endring av artikkel feilet',
},
});
}

export function fetchAll({
Expand Down
32 changes: 9 additions & 23 deletions app/actions/CompanyActions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { push } from 'redux-first-history';
import { addToast } from 'app/actions/ToastActions';
import callAPI from 'app/actions/callAPI';
import {
companySchema,
Expand All @@ -12,7 +10,6 @@ import { semesterToText } from '../routes/companyInterest/utils';
import { Company, Event, Joblistings } from './ActionTypes';
import type { CompanySemesterEntity } from 'app/reducers/companySemesters';
import type { FormValues as CompanyContactEditorFormValues } from 'app/routes/bdb/components/CompanyContactEditor';
import type { AppDispatch } from 'app/store/createStore';
import type { ID } from 'app/store/models';
import type {
AdminListCompany,
Expand Down Expand Up @@ -131,26 +128,15 @@ export function editCompany({ companyId, ...data }: Record<string, any>) {
}

export function deleteCompany(companyId: ID) {
return (dispatch: AppDispatch) => {
return dispatch(
callAPI({
types: Company.DELETE,
endpoint: `/bdb/${companyId}/`,
method: 'DELETE',
meta: {
id: Number(companyId),
errorMessage: 'Sletting av bedrift feilet',
},
})
).then(() => {
dispatch(
addToast({
message: 'Bedrift slettet.',
})
);
dispatch(push('/bdb/'));
});
};
return callAPI({
types: Company.DELETE,
endpoint: `/bdb/${companyId}/`,
method: 'DELETE',
meta: {
id: Number(companyId),
errorMessage: 'Sletting av bedrift feilet',
},
});
}

export function addSemesterStatus({ companyId, ...data }: Record<string, any>) {
Expand Down
12 changes: 9 additions & 3 deletions app/actions/CompanyInterestActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { companyInterestSchema } from 'app/reducers';
import { CompanyInterestForm } from './ActionTypes';
import type { CompanyInterestEntity } from 'app/reducers/companyInterest';
import type { AppDispatch } from 'app/store/createStore';
import type { ID } from 'app/store/models';
import type {
DetailedCompanyInterest,
ListCompanyInterest,
Expand All @@ -20,7 +21,8 @@ export function fetchAll() {
},
});
}
export function fetchCompanyInterest(companyInterestId: number) {

export function fetchCompanyInterest(companyInterestId: ID) {
return callAPI<DetailedCompanyInterest>({
types: CompanyInterestForm.FETCH,
endpoint: `/company-interests/${companyInterestId}/`,
Expand All @@ -30,6 +32,7 @@ export function fetchCompanyInterest(companyInterestId: number) {
},
});
}

export function createCompanyInterest(
data: CompanyInterestEntity,
isEnglish: boolean
Expand Down Expand Up @@ -57,7 +60,8 @@ export function createCompanyInterest(
);
};
}
export function deleteCompanyInterest(id: number) {

export function deleteCompanyInterest(id: ID) {
return (dispatch: AppDispatch) => {
return dispatch(
callAPI({
Expand All @@ -78,7 +82,8 @@ export function deleteCompanyInterest(id: number) {
);
};
}
export function updateCompanyInterest(id: number, data: CompanyInterestEntity) {

export function updateCompanyInterest(id: ID, data: CompanyInterestEntity) {
return (dispatch: AppDispatch) => {
return dispatch(
callAPI({
Expand All @@ -95,6 +100,7 @@ export function updateCompanyInterest(id: number, data: CompanyInterestEntity) {
);
};
}

export function fetch({
next,
filters,
Expand Down
50 changes: 19 additions & 31 deletions app/actions/EventActions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { push } from 'redux-first-history';
import { addToast } from 'app/actions/ToastActions';
import callAPI from 'app/actions/callAPI';
import {
eventSchema,
Expand Down Expand Up @@ -159,38 +157,28 @@ export function fetchAllergies(eventId: ID) {
}

export function createEvent(event: Record<string, any>) {
return (dispatch: AppDispatch) =>
dispatch(
callAPI<UnknownEvent>({
types: Event.CREATE,
endpoint: '/events/',
method: 'POST',
body: event,
schema: eventSchema,
meta: {
errorMessage: 'Opprettelse av arrangement feilet',
},
})
).then(
(action) =>
'success' in action &&
dispatch(push(`/events/${action.payload.result}/`))
);
return callAPI<UnknownEvent>({
types: Event.CREATE,
endpoint: '/events/',
method: 'POST',
body: event,
schema: eventSchema,
meta: {
errorMessage: 'Opprettelse av arrangement feilet',
},
});
}

export function editEvent(event: Record<string, any>) {
return (dispatch) =>
dispatch(
callAPI({
types: Event.EDIT,
endpoint: `/events/${event.id}/`,
method: 'PUT',
body: { ...event, cover: event.cover || undefined },
meta: {
errorMessage: 'Endring av arrangement feilet',
},
})
).then(() => dispatch(push(`/events/${event.id}`)));
return callAPI({
types: Event.EDIT,
endpoint: `/events/${event.id}/`,
method: 'PUT',
body: { ...event, cover: event.cover || undefined },
meta: {
errorMessage: 'Endring av arrangement feilet',
},
});
}

export function deleteEvent(eventId: ID) {
Expand Down
4 changes: 2 additions & 2 deletions app/actions/GalleryActions.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import callAPI from 'app/actions/callAPI';
import { gallerySchema } from 'app/reducers';
import { Gallery } from './ActionTypes';
import { FormValues as GalleryEditorFormValues } from 'app/routes/photos/components/GalleryEditor';
import type { Thunk } from 'app/types';
import type { FormValues as GalleryEditorFormValues } from 'app/routes/photos/components/GalleryEditor';
import type { ID } from 'app/store/models';
import type { DetailedGallery } from 'app/store/models/Gallery';
import type { Thunk } from 'app/types';

export function fetch({
next,
Expand Down
44 changes: 18 additions & 26 deletions app/actions/GroupActions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { push } from 'redux-first-history';
import callAPI from 'app/actions/callAPI';
import { groupSchema, membershipSchema } from 'app/reducers';
import { Group, Membership } from './ActionTypes';
Expand Down Expand Up @@ -83,31 +82,24 @@ export function fetchAllWithType(type: GroupType) {
}

export function editGroup(group: Record<string, any>) {
return (dispatch: AppDispatch) =>
dispatch(
callAPI({
types: Group.UPDATE,
endpoint: `/groups/${group.id}/`,
schema: groupSchema,
method: 'PATCH',
body: group,
meta: {
group,
errorMessage:
group.type === 'interesse'
? 'Endring av interessegruppe feilet'
: 'Oppdatering av gruppe feilet',
successMessage:
group.type === 'interesse'
? 'Endring av interessegruppe fullført'
: 'Oppdatering av gruppe fullført',
},
})
).then(() =>
group.type === 'interesse'
? dispatch(push(`/interest-groups/${group.id}`))
: null
);
return callAPI({
types: Group.UPDATE,
endpoint: `/groups/${group.id}/`,
schema: groupSchema,
method: 'PATCH',
body: group,
meta: {
group,
errorMessage:
group.type === 'interesse'
? 'Endring av interessegruppe feilet'
: 'Oppdatering av gruppe feilet',
successMessage:
group.type === 'interesse'
? 'Endring av interessegruppe fullført'
: 'Oppdatering av gruppe fullført',
},
});
}

export function joinGroup(groupId: ID, user: CurrentUser, role = 'member') {
Expand Down

0 comments on commit e092e4c

Please sign in to comment.