Save extra state to server

This commit is contained in:
Justin Edmund 2022-02-04 14:47:34 -08:00
parent b42bef99fe
commit cface6a107
2 changed files with 6 additions and 3 deletions

View file

@ -57,9 +57,11 @@ const Party = (props: Props) => {
}
// Methods: Updating the party's extra flag
// Note: This doesn't save to the server yet.
function checkboxChanged(event: React.ChangeEvent<HTMLInputElement>) {
setHasExtra(event.target.checked)
api.endpoints.parties.update(id, {
'party': { 'is_extra': event.target.checked }
}, headers)
}
// Methods: Navigating with segmented control

View file

@ -8,13 +8,14 @@ type CollectionEndpoint = ({ query }: { query: AxiosRequestConfig }) => Promise<
type IdEndpoint = ({ id }: { id: string }) => Promise<AxiosResponse<any>>
type IdWithObjectEndpoint = ({ id, object }: { id: string, object: string }) => Promise<AxiosResponse<any>>
type PostEndpoint = (object: {}, headers?: {}) => Promise<AxiosResponse<any>>
type PutEndpoint = (id: string, object: {}, headers?: {}) => Promise<AxiosResponse<any>>
interface EndpointMap {
getAll: CollectionEndpoint
getOne: IdEndpoint
getOneWithObject: IdWithObjectEndpoint
create: PostEndpoint
update: PostEndpoint
update: PutEndpoint
destroy: IdEndpoint
}
@ -43,7 +44,7 @@ class Api {
getOne: ({ id }: { id: string }) => axios.get(`${resourceUrl}/${id}/`),
getOneWithObject: ({ id, object }: { id: string, object: string }) => axios.get(`${resourceUrl}/${id}/${object}`),
create: (object: {}, headers?: {}) => axios.post(resourceUrl, object, headers),
update: (object: {}, headers?: {}) => axios.put(resourceUrl, object, headers),
update: (id: string, object: {}, headers?: {}) => axios.put(`${resourceUrl}/${id}`, object, headers),
destroy: ({ id }: { id: string }) => axios.delete(`${resourceUrl}/${id}`)
} as EndpointMap
}