-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bab4196
commit de87091
Showing
18 changed files
with
261 additions
and
52 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,53 @@ | ||
import {RouterDialog, RouterDialogAction} from "../../../components/RouterDialog.tsx"; | ||
import {t, Trans} from "@lingui/macro"; | ||
import {useActionData} from "react-router-dom"; | ||
import {OptionalErrorResponseBody} from "../../../utils/responses.ts"; | ||
import {translateErrorCode} from "../../../gql"; | ||
import {JidCodeInput} from "../../../components/JidCodeInput.tsx"; | ||
import {useState} from "react"; | ||
|
||
export const AdminCreateEvent = () => { | ||
const [jidCode, setJidCode] = useState<string>(""); | ||
|
||
const actionData = useActionData() as OptionalErrorResponseBody; | ||
|
||
const error = actionData?.errorCode | ||
? translateErrorCode(actionData.errorCode) | ||
: actionData?.error; | ||
|
||
const dialogActions: RouterDialogAction[] = [{ | ||
label: <Trans>Cancel</Trans>, | ||
type: "button", | ||
callback: callback => callback.cancel(), | ||
}, { | ||
label: <Trans>Create</Trans>, | ||
type: "submit", | ||
name: "createButton", | ||
classNames: "btn-primary", | ||
}]; | ||
|
||
return ( | ||
<RouterDialog title={<Trans>Add event</Trans>} actions={dialogActions}> | ||
<label className="form-control w-full"> | ||
<JidCodeInput | ||
style={"form"} | ||
name="code" | ||
onValidJidCode={() => { | ||
}} jidCode={jidCode} | ||
setJidCode={setJidCode}/> | ||
</label> | ||
<label className="form-control w-full mt-4"> | ||
<input type="number" | ||
placeholder={t`Location name`} | ||
required={true} | ||
defaultValue={new Date().getFullYear()} | ||
autoComplete="off" | ||
name="year" | ||
className={`input input-bordered w-full`}/> | ||
</label> | ||
{error && <div className="label"> | ||
<span className="label-text text-error">{error}</span> | ||
</div>} | ||
</RouterDialog> | ||
) | ||
} |
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,5 @@ | ||
mutation CreateEvent($input: CreateEventInput!) { | ||
createEvent(input: $input) { | ||
id | ||
} | ||
} |
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,34 @@ | ||
import {ActionFunctionArgs, replace} from "react-router-dom"; | ||
import {client, CreateEventDocument, hasErrorCode, ServerErrorCode} from "../../../gql"; | ||
import {badRequest} from "../../../utils/responses.ts"; | ||
|
||
export const adminCreateEventAction = async ({params, request}: ActionFunctionArgs) => { | ||
const formData = await request.formData(); | ||
|
||
if (formData.has("createButton") && formData.get("code") && formData.get("year")) { | ||
const locationId = params.locationId as string; | ||
const code = formData.get("code") as string; | ||
const year = +(formData.get("year") as string); | ||
|
||
const result = await client.mutation(CreateEventDocument, { | ||
input: { | ||
locationId, | ||
code, | ||
year, | ||
active: false, | ||
} | ||
}); | ||
|
||
if (result.error) { | ||
if (hasErrorCode(result.error, ServerErrorCode.EVENT_CODE_AND_YEAR_NOT_AVAILABLE)) { | ||
return badRequest({errorCode: ServerErrorCode.EVENT_CODE_AND_YEAR_NOT_AVAILABLE}); | ||
} else { | ||
return badRequest({error: result.error.message}); | ||
} | ||
} | ||
|
||
return replace(`/admin/locations/$\{params.locationId}/events/${result.data?.createEvent?.id}`); | ||
} | ||
|
||
return replace(`/admin/locations/${params.locationId}`); | ||
} |
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,2 @@ | ||
export * from "./adminCreateEventAction.ts"; | ||
export * from "./AdminCreateEvent.tsx"; |
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
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
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 |
---|---|---|
|
@@ -12,6 +12,7 @@ query GetEvent($code: String!) { | |
event(code: $code) { | ||
id | ||
location { | ||
id | ||
name | ||
owners { | ||
id | ||
|
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
Oops, something went wrong.