-
Notifications
You must be signed in to change notification settings - Fork 37
Added SCEvents ability to create event #2070
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+595
−30
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8684d3f
Added SCEvents ability to create event
maernest04 c314b9a
Fix indent issues
maernest04 0883c7e
Modified the scevents api port
maernest04 edafd59
Simplified code, removed unnecessary functions
maernest04 15ebf1d
Implement event registration logic for SCEvents (#2073)
KhoaNguyen706 978ab53
Added SCEvents ability to create event
maernest04 6e8ad19
Fixing rebase problems
maernest04 05ed46e
Made changes to SCEvents.js with Steven's comments
maernest04 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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,55 +1,57 @@ | ||
| import { ApiResponse } from './ApiResponses'; | ||
|
|
||
| const SCEVENTS_API_URL = 'http://localhost:8080'; | ||
| const SCEVENTS_API_URL = 'http://localhost:8002'; | ||
|
|
||
| export async function getAllSCEvents() { | ||
| let status = new ApiResponse(); | ||
|
|
||
| const status = new ApiResponse(); | ||
| try { | ||
| const url = new URL('/events/', SCEVENTS_API_URL); | ||
| const res = await fetch(url.href, { | ||
| method: 'GET', | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| }); | ||
|
|
||
| if (res.ok) { | ||
| const result = await res.json(); | ||
| status.responseData = result; | ||
| } else { | ||
| const res = await fetch(`${SCEVENTS_API_URL}/events/`); | ||
| const result = await res.json(); | ||
| status.responseData = result; | ||
| if (!res.ok) { | ||
| status.error = true; | ||
| } | ||
| } catch (err) { | ||
| status.error = true; | ||
| status.responseData = err; | ||
| status.error = true; | ||
| } | ||
|
|
||
| return status; | ||
| } | ||
|
|
||
| export async function getEventByID(id) { | ||
| let status = new ApiResponse(); | ||
| const status = new ApiResponse(); | ||
| try { | ||
| const res = await fetch(`${SCEVENTS_API_URL}/events/${id}`); | ||
| const result = await res.json(); | ||
| status.responseData = result; | ||
| if (!res.ok) { | ||
| status.error = true; | ||
| } | ||
| } catch (err) { | ||
| status.error = true; | ||
| status.responseData = err; | ||
| } | ||
| return status; | ||
| } | ||
|
|
||
| export async function createSCEvent(eventBody) { | ||
| const status = new ApiResponse(); | ||
| try { | ||
| const url = new URL(`/events/${id}`, SCEVENTS_API_URL); | ||
| const res = await fetch(url.href, { | ||
| method: 'GET', | ||
| const res = await fetch(`${SCEVENTS_API_URL}/events/`, { | ||
| method: 'POST', | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| body: JSON.stringify(eventBody), | ||
| }); | ||
|
|
||
| if (res.ok) { | ||
| const result = await res.json(); | ||
| status.responseData = result; | ||
| } else { | ||
| const body = await res.json(); | ||
| status.responseData = body; | ||
| if (!res.ok) { | ||
| status.error = true; | ||
| } | ||
| } catch (err) { | ||
| status.error = true; | ||
| status.responseData = err; | ||
| } | ||
|
|
||
| return status; | ||
| } | ||
This file contains hidden or 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 hidden or 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,116 @@ | ||
| /* eslint-disable camelcase -- SCEvents registration question shape uses snake_case */ | ||
| import React from 'react'; | ||
|
|
||
| export default function CreateEventFormQuestionBlock({ | ||
| question, | ||
| index, | ||
| onUpdateField, | ||
| onChangeType, | ||
| onRemove, | ||
| onUpdateAnswerOption, | ||
| onAddAnswerOption, | ||
| onRemoveAnswerOption, | ||
| }) { | ||
| return ( | ||
| <div className="p-4 mb-3 border border-gray-200 rounded-lg shadow-sm bg-white dark:bg-gray-800 dark:border-gray-700"> | ||
| <div className="flex flex-col gap-3 sm:flex-row sm:items-start"> | ||
| <div className="flex flex-wrap flex-1 gap-2 items-center"> | ||
| <span className="flex justify-center items-center w-6 h-6 text-xs font-medium rounded-full bg-primary/15 text-primary"> | ||
| {index + 1} | ||
| </span> | ||
| <select | ||
| value={question.type} | ||
| onChange={(e) => onChangeType(question.id, e.target.value)} | ||
| className="text-sm select select-bordered select-sm dark:bg-gray-700" | ||
| > | ||
| <option value="textbox">Text input</option> | ||
| <option value="multiple_choice">Multiple choice</option> | ||
| <option value="dropdown">Dropdown</option> | ||
| <option value="checkbox">Checkbox</option> | ||
| </select> | ||
| <label className="flex gap-2 items-center text-sm cursor-pointer label"> | ||
| <input | ||
| type="checkbox" | ||
| checked={!!question.required} | ||
| onChange={(e) => onUpdateField(question.id, 'required', e.target.checked)} | ||
| className="checkbox checkbox-sm" | ||
| /> | ||
| <span className="label-text">Required</span> | ||
| </label> | ||
| </div> | ||
| <button | ||
| type="button" | ||
| className="btn btn-outline btn-sm shrink-0" | ||
| onClick={() => onRemove(question.id)} | ||
| > | ||
| Remove | ||
| </button> | ||
| </div> | ||
|
|
||
| <label className="w-full mt-3 form-control"> | ||
| <div className="label"> | ||
| <span className="label-text">Question text</span> | ||
| </div> | ||
| <input | ||
| type="text" | ||
| className="w-full text-sm input input-bordered sm:text-base" | ||
| value={question.question} | ||
| onChange={(e) => onUpdateField(question.id, 'question', e.target.value)} | ||
| placeholder="Question" | ||
| /> | ||
| </label> | ||
|
|
||
| {question.type === 'textbox' && ( | ||
| <div className="flex gap-2 items-center mt-2 text-sm"> | ||
| <span className="text-gray-500 dark:text-gray-400">Max characters</span> | ||
| <input | ||
| type="number" | ||
| min="1" | ||
| className="w-24 input input-bordered input-sm" | ||
| value={question.answer_details?.max_chars ?? ''} | ||
| onChange={(e) => | ||
| onUpdateField(question.id, 'answer_details', { | ||
| max_chars: e.target.value ? parseInt(e.target.value, 10) : undefined, | ||
| }) | ||
| } | ||
| placeholder="None" | ||
| /> | ||
| </div> | ||
| )} | ||
|
|
||
| {(question.type === 'multiple_choice' || question.type === 'dropdown') && ( | ||
| <div className="mt-3 space-y-2"> | ||
| <span className="text-sm text-gray-500 dark:text-gray-400">Answer options</span> | ||
| {(question.answer_options || []).map((option, optIndex) => ( | ||
| <div key={`${question.id}-opt-${optIndex}`} className="flex gap-2 items-center"> | ||
| <input | ||
| type="text" | ||
| className="flex-1 text-sm input input-bordered input-sm" | ||
| value={option} | ||
| onChange={(e) => onUpdateAnswerOption(question.id, optIndex, e.target.value)} | ||
| placeholder={`Option ${optIndex + 1}`} | ||
| /> | ||
| {(question.answer_options || []).length > 1 && ( | ||
| <button | ||
| type="button" | ||
| className="btn btn-outline btn-sm btn-square" | ||
| onClick={() => onRemoveAnswerOption(question.id, optIndex)} | ||
| aria-label="Remove option" | ||
| > | ||
| × | ||
| </button> | ||
| )} | ||
| </div> | ||
| ))} | ||
| <button | ||
| type="button" | ||
| className="w-full btn btn-outline btn-sm" | ||
| onClick={() => onAddAnswerOption(question.id)} | ||
| > | ||
| Add option | ||
| </button> | ||
| </div> | ||
| )} | ||
| </div> | ||
| ); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.