mirror of
https://github.com/baptisteArno/typebot.io.git
synced 2026-06-22 21:06:40 +08:00
🔧 Refactor content retrieval logic across various input parsing functions to use logical OR for default values
This commit is contained in:
parent
c8cfa6a66e
commit
1925569b4a
@ -92,11 +92,12 @@ export const parseCardsReply = (
|
||||
newSetVariableHistory = updatedSetVariableHistory;
|
||||
}
|
||||
|
||||
const content = matchedItem.title || matchedItem.imageUrl;
|
||||
if (!content) return { status: "fail" };
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
content: isNotEmpty(matchedItem.title)
|
||||
? matchedItem.title
|
||||
: (matchedItem.imageUrl ?? ""),
|
||||
content,
|
||||
outgoingEdgeId: matchedPath?.outgoingEdgeId,
|
||||
newSessionState,
|
||||
newSetVariableHistory,
|
||||
|
||||
@ -27,9 +27,12 @@ export const parseSingleChoiceReply = (
|
||||
|
||||
if (!matchedItem) return { status: "fail" };
|
||||
|
||||
const content = matchedItem.value || parseItemContent(matchedItem);
|
||||
if (!content) return { status: "fail" };
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
content: matchedItem.value ?? parseItemContent(matchedItem) ?? "",
|
||||
content: matchedItem.value ?? parseItemContent(matchedItem),
|
||||
outgoingEdgeId: matchedItem.outgoingEdgeId,
|
||||
};
|
||||
};
|
||||
|
||||
@ -14,13 +14,13 @@ export const parseDateReply = (
|
||||
block: DateInputBlock,
|
||||
): ParsedReply => {
|
||||
const parsedDate = (
|
||||
block.options?.format ?? defaultDateInputOptions.format
|
||||
block.options?.format || defaultDateInputOptions.format
|
||||
).startsWith("dd")
|
||||
? chronoParser.GB.parse(reply)
|
||||
: chronoParser.parse(reply);
|
||||
if (parsedDate.length === 0) return { status: "fail" };
|
||||
const formatString =
|
||||
block.options?.format ??
|
||||
block.options?.format ||
|
||||
(block.options?.hasTime
|
||||
? defaultDateInputOptions.formatWithTime
|
||||
: defaultDateInputOptions.format);
|
||||
|
||||
@ -46,7 +46,7 @@ const createStripePaymentIntent = async (
|
||||
: stripeKeys.live.secretKey,
|
||||
{ apiVersion: "2024-09-30.acacia" },
|
||||
);
|
||||
const currency = options?.currency ?? defaultPaymentInputOptions.currency;
|
||||
const currency = options?.currency || defaultPaymentInputOptions.currency;
|
||||
const amount = Math.round(
|
||||
Number(parseVariables(options.amount, { variables, sessionStore })) *
|
||||
(isZeroDecimalCurrency(currency) ? 1 : 100),
|
||||
|
||||
@ -2,4 +2,4 @@ import { defaultRatingInputOptions } from "@typebot.io/blocks-inputs/rating/cons
|
||||
import type { RatingInputBlock } from "@typebot.io/blocks-inputs/rating/schema";
|
||||
|
||||
export const validateRatingReply = (reply: string, block: RatingInputBlock) =>
|
||||
Number(reply) <= (block.options?.length ?? defaultRatingInputOptions.length);
|
||||
Number(reply) <= (block.options?.length || defaultRatingInputOptions.length);
|
||||
|
||||
@ -16,7 +16,7 @@ export const parseTime = (
|
||||
status: "success",
|
||||
content: format(
|
||||
parsedDate,
|
||||
options?.format ?? defaultTimeInputOptions.format,
|
||||
options?.format || defaultTimeInputOptions.format,
|
||||
),
|
||||
};
|
||||
};
|
||||
|
||||
@ -15,7 +15,7 @@ const parseSetUserCode = (
|
||||
) =>
|
||||
user?.email || user?.id
|
||||
? `
|
||||
window.$chatwoot.setUser(${user?.id ?? user.email ?? `"${resultId}"`}, {
|
||||
window.$chatwoot.setUser(${user?.id || user.email || `"${resultId}"`}, {
|
||||
email: ${user?.email ? user.email : "undefined"},
|
||||
name: ${user?.name ? user.name : "undefined"},
|
||||
avatar_url: ${user?.avatarUrl ? user.avatarUrl : "undefined"},
|
||||
|
||||
@ -33,7 +33,7 @@ import type { Group } from "@typebot.io/groups/schemas";
|
||||
import { parseAllowedFileTypesMetadata } from "@typebot.io/lib/extensionFromMimeType";
|
||||
import { isURL } from "@typebot.io/lib/isURL";
|
||||
import { parseUnknownError } from "@typebot.io/lib/parseUnknownError";
|
||||
import { byId, isDefined } from "@typebot.io/lib/utils";
|
||||
import { byId, isDefined, isNotEmpty } from "@typebot.io/lib/utils";
|
||||
import type { AnswerInSessionState } from "@typebot.io/results/schemas/answers";
|
||||
import type { SessionStore } from "@typebot.io/runtime-session-store";
|
||||
import { defaultSystemMessages } from "@typebot.io/settings/constants";
|
||||
|
||||
@ -7,5 +7,5 @@ export const parseItemContent = (
|
||||
// Buttons
|
||||
if ("content" in item) return item.content;
|
||||
// Picture choice
|
||||
if ("title" in item) return item.title ?? item.pictureSrc;
|
||||
if ("title" in item) return item.title || item.pictureSrc;
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user