Skip to content

Commit

Permalink
feat: let admin choose whether to support multiple responses for cust…
Browse files Browse the repository at this point in the history
…om options or not
  • Loading branch information
oreHGA committed Jan 6, 2025
1 parent 186ea0c commit 98f0af6
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions frontend/src/@types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export type PromptAdditionalMeta = {
category?: string;
isNotificationActive?: boolean;
customOptionText?: string; // ; separated list of options
singleResponse?: boolean;
questId?: string;
notifyCondition?: PromptNotifyCondition;
};
Expand Down
24 changes: 24 additions & 0 deletions frontend/src/components/quest/addprompts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const AddPromptModal: React.FC<AddPromptModalProps> = ({
const [customOptions, setCustomOptions] = useState<string[]>(
prompt.additionalMeta.customOptionText ? prompt.additionalMeta.customOptionText.split(";") : []
);
const [singleResponse, setSingleResponse] = useState(prompt.additionalMeta.singleResponse);
const [responseType, setResponseType] = useState<PromptResponseType | null>(prompt.responseType);
const [category, setCategory] = useState<string | null>(prompt.additionalMeta.category ?? null);
const [countPerDay, setCountPerDay] = useState<number | undefined>();
Expand Down Expand Up @@ -67,6 +68,7 @@ const AddPromptModal: React.FC<AddPromptModalProps> = ({
additionalMeta: {
category: category ?? "",
customOptionText: customOptions.join(";"),
singleResponse: singleResponse,
}, // Initialize with an empty object
};

Expand Down Expand Up @@ -194,6 +196,28 @@ const AddPromptModal: React.FC<AddPromptModalProps> = ({
</span>
))}
</div>
<div className="flex flex-col">
<label htmlFor="singleResponse" className="ml-2 text-sm font-medium text-gray-900 dark:text-white">
Allow multiple responses
</label>
<select
id="singleResponse"
value={singleResponse ? "no" : "yes"}
onChange={(e) => {
if (e.target.value === "yes") {
setSingleResponse(false);
} else {
setSingleResponse(true);
}
}}
className="block w-full rounded-lg border border-gray-300 bg-gray-50 p-2.5 text-sm text-gray-900 focus:border-indigo-500 focus:ring-indigo-500 dark:border-gray-600 dark:bg-gray-700 dark:text-white dark:placeholder-gray-400 dark:focus:border-indigo-500 dark:focus:ring-indigo-500"
>
<option value="yes" selected>
Yes
</option>
<option value="no">No</option>
</select>
</div>
</div>
)}
</label>
Expand Down
1 change: 1 addition & 0 deletions mobile/src/@types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export type PromptAdditionalMeta = {
category?: string;
isNotificationActive?: boolean;
customOptionText?: string; // ; separated list of options
singleResponse?: boolean; // if true, only one response is allowed during custom option selection
questId?: string;
notifyCondition?: PromptNotifyCondition;
};
Expand Down
5 changes: 4 additions & 1 deletion mobile/src/pages/prompt-entry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,10 @@ export function PromptEntryScreen() {
title={option}
isActive={userResponse.split(";").includes(option)}
handleValueChange={() => {
if (prompt.additionalMeta.questId) {
if (
prompt.additionalMeta.questId &&
prompt.additionalMeta.singleResponse
) {
// only allow single question response
setUserResponse(option);
} else {
Expand Down

0 comments on commit 98f0af6

Please sign in to comment.