generated from ocadotechnology/codeforlife-template-frontend
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add hook for session cookie * Call contributor endpoint * add contributor routes * fix path and delete fruit * add service name and call backend * Add contributor endpoint * add agreement signature endpoints * Add create endpoint * add new endpoint definition * check sign endpoint * add login endpoint * check endpoint functionality * Fix url and test functionality * Fix type * Remove pages * remove unused import
- Loading branch information
Showing
19 changed files
with
641 additions
and
625 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import { | ||
type CreateArg, | ||
type CreateResult, | ||
type ListArg, | ||
type ListResult, | ||
type Model, | ||
type RetrieveArg, | ||
type RetrieveResult, | ||
buildUrl, | ||
modelUrls, | ||
tagData, | ||
} from "codeforlife/utils/api" | ||
|
||
import api from "." | ||
|
||
export type AgreementSignature = Model< | ||
number, | ||
{ | ||
contributor: number | ||
agreement_id: string | ||
signed_at: Date | ||
} | ||
> | ||
|
||
const agreementSignatureUrls = modelUrls( | ||
"agreement-signatures/", | ||
"agreement-signatures/<id>/", | ||
) | ||
|
||
export type RetrieveAgreementSignatureResult = RetrieveResult< | ||
AgreementSignature, | ||
"contributor" | "agreement_id" | "signed_at" | ||
> | ||
export type RetrieveAgreementSignatureArg = RetrieveArg<AgreementSignature> | ||
|
||
export type ListAgreementSignaturesResult = ListResult< | ||
AgreementSignature, | ||
"contributor" | "agreement_id" | "signed_at" | ||
> | ||
export type ListAgreementSignaturesArg = ListArg | ||
|
||
export type CreateAgreementSignatureResult = CreateResult< | ||
AgreementSignature, | ||
"contributor" | "agreement_id" | "signed_at" | ||
> | ||
export type CreateAgreementSignatureArg = CreateArg< | ||
AgreementSignature, | ||
"contributor" | "agreement_id" | "signed_at" | ||
> | ||
|
||
export type CheckSignedAgreementSignatureResult = | ||
| { latest_commit_id: string; status: 404 | 451 } | ||
| { status: 200 } | ||
export type CheckSignedAgreementSignatureArg = { contributor_pk: number } | ||
|
||
const agreementSignatureApi = api.injectEndpoints({ | ||
endpoints: build => ({ | ||
retrieveAgreementSignature: build.query< | ||
RetrieveAgreementSignatureResult, | ||
RetrieveAgreementSignatureArg | ||
>({ | ||
query: id => ({ | ||
url: buildUrl(agreementSignatureUrls.detail, { url: { id } }), | ||
method: "GET", | ||
}), | ||
providesTags: tagData("AgreementSignature"), | ||
}), | ||
listAgreementSignatures: build.query< | ||
ListAgreementSignaturesResult, | ||
ListAgreementSignaturesArg | ||
>({ | ||
query: search => ({ | ||
url: buildUrl(agreementSignatureUrls.list, { search }), | ||
method: "GET", | ||
}), | ||
providesTags: tagData("AgreementSignature", { includeListTag: true }), | ||
}), | ||
createAgreementSignature: build.mutation< | ||
CreateAgreementSignatureResult, | ||
CreateAgreementSignatureArg | ||
>({ | ||
query: body => ({ | ||
url: agreementSignatureUrls.list, | ||
method: "POST", | ||
body, | ||
}), | ||
invalidatesTags: tagData("AgreementSignature", { includeListTag: true }), | ||
}), | ||
checkSignedAgreementSignature: build.query< | ||
CheckSignedAgreementSignatureResult, | ||
CheckSignedAgreementSignatureArg | ||
>({ | ||
query: ({ contributor_pk }) => ({ | ||
url: buildUrl( | ||
agreementSignatureUrls.list + `check-signed/${contributor_pk}`, | ||
{ | ||
url: { contributor_pk }, | ||
}, | ||
), | ||
method: "GET", | ||
}), | ||
}), | ||
}), | ||
}) | ||
|
||
export default agreementSignatureApi | ||
export const { | ||
useRetrieveAgreementSignatureQuery, | ||
useLazyRetrieveAgreementSignatureQuery, | ||
useListAgreementSignaturesQuery, | ||
useLazyListAgreementSignaturesQuery, | ||
useCreateAgreementSignatureMutation, | ||
useCheckSignedAgreementSignatureQuery, | ||
} = agreementSignatureApi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { | ||
type ListArg, | ||
type ListResult, | ||
type Model, | ||
type RetrieveArg, | ||
type RetrieveResult, | ||
buildUrl, | ||
modelUrls, | ||
tagData, | ||
} from "codeforlife/utils/api" | ||
|
||
import api from "." | ||
|
||
export type Contributor = Model< | ||
number, | ||
{ | ||
email: string | ||
name: string | ||
location?: string | ||
html_url: string | ||
avatar_url: string | ||
last_login?: Date | ||
} | ||
> | ||
|
||
const contributorUrls = modelUrls("contributors/", "contributors/<id>/") | ||
|
||
export type RetrieveContributorResult = RetrieveResult< | ||
Contributor, | ||
"email" | "name" | "location" | "html_url" | "avatar_url" | "last_login" | ||
> | ||
export type RetrieveContributorArg = RetrieveArg<Contributor> | ||
|
||
export type ListContributorsResult = ListResult< | ||
Contributor, | ||
"email" | "name" | "location" | "html_url" | "avatar_url" | "last_login" | ||
> | ||
export type ListContributorsArg = ListArg | ||
|
||
const contributorApi = api.injectEndpoints({ | ||
endpoints: build => ({ | ||
retrieveContributor: build.query< | ||
RetrieveContributorResult, | ||
RetrieveContributorArg | ||
>({ | ||
query: id => ({ | ||
url: buildUrl(contributorUrls.detail, { url: { id } }), | ||
method: "GET", | ||
}), | ||
providesTags: tagData("Contributor"), | ||
}), | ||
listContributors: build.query<ListContributorsResult, ListContributorsArg>({ | ||
query: search => ({ | ||
url: buildUrl(contributorUrls.list, { search }), | ||
method: "GET", | ||
}), | ||
providesTags: tagData("Contributor", { includeListTag: true }), | ||
}), | ||
}), | ||
}) | ||
|
||
export default contributorApi | ||
export const { | ||
useRetrieveContributorQuery, | ||
useLazyRetrieveContributorQuery, | ||
useListContributorsQuery, | ||
useLazyListContributorsQuery, | ||
} = contributorApi |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { type SessionMetadata } from "../app/hooks" | ||
|
||
export type LoginWithGithubResult = SessionMetadata | ||
export type LoginWithGithubArg = { code: string } | ||
|
||
import api from "." | ||
|
||
const sessionApi = api.injectEndpoints({ | ||
endpoints: build => ({ | ||
loginWithGithub: build.mutation<LoginWithGithubResult, LoginWithGithubArg>({ | ||
query: body => ({ | ||
url: "session/login/", | ||
method: "POST", | ||
body, | ||
}), | ||
}), | ||
}), | ||
}) | ||
|
||
export const { useLoginWithGithubMutation } = sessionApi | ||
export default sessionApi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +0,0 @@ | ||
import * as yup from "yup" | ||
|
||
export const fruitNameSchema = yup.string().max(50) | ||
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +0,0 @@ | ||
export { default as FruitNameField } from "./FruitNameField" | ||
export * from "./FruitNameField" | ||
Oops, something went wrong.