feat:update form
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
import type { QuestionType } from "@/db/schema/form";
|
||||
|
||||
export type FormAnswerValue = string | string[];
|
||||
export type FormAnswerPayload = {
|
||||
questionId: string;
|
||||
value: FormAnswerValue;
|
||||
imageCdnId?: string | null;
|
||||
};
|
||||
|
||||
export function decodeCheckboxAnswer(value: FormAnswerValue | undefined): string[] {
|
||||
if (Array.isArray(value)) {
|
||||
@@ -39,3 +44,14 @@ export function formatStoredAnswer(
|
||||
? decodeCheckboxAnswer(value).join(", ")
|
||||
: value;
|
||||
}
|
||||
|
||||
export function answerCellValue(
|
||||
value: string | undefined,
|
||||
questionType: QuestionType | string,
|
||||
imageCdnId?: string | null,
|
||||
) {
|
||||
const text = formatStoredAnswer(value, questionType);
|
||||
const imageUrl = imageCdnId ? `/cdn/${imageCdnId}` : "";
|
||||
if (text && imageUrl) return `${text}\n${imageUrl}`;
|
||||
return text || imageUrl;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user