Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ object SurveyManager {
val actionClasses = environmentDataHolder?.data?.data?.actionClasses ?: listOf()
val codeActionClasses = actionClasses.filter { it.type == "code" }
val actionClass = codeActionClasses.firstOrNull { it.key == action }
if (actionClass == null) {
val error = RuntimeException("\"$action\" action unknown. Please add this action in Formbricks first in order to use it in your code.")
Logger.e(error)
return
}
val firstSurveyWithActionClass = filteredSurveys.firstOrNull { survey ->
val triggers = survey.triggers ?: listOf()
triggers.firstOrNull { trigger ->
Expand Down Expand Up @@ -183,6 +188,10 @@ object SurveyManager {
firstSurveyWithActionClass.id.let {
isShowingSurvey = true
val timeout = firstSurveyWithActionClass.delay ?: 0.0
if (timeout > 0.0) {
val surveyName = firstSurveyWithActionClass.name
Logger.d("Delaying survey \"$surveyName\" by $timeout seconds")
}
stopDisplayTimer()
displayTimer.schedule(object : TimerTask() {
override fun run() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,14 @@ data class Survey(
@SerializedName("segment") val segment: Segment?,
@SerializedName("styling") val styling: Styling?,
@SerializedName("languages") val languages: List<SurveyLanguage>?,
@SerializedName("projectOverwrites") val projectOverwrites: SurveyProjectOverwrites? = null
)

@Serializable
data class SurveyProjectOverwrites(
@SerializedName("brandColor") val brandColor: String? = null,
@SerializedName("highlightBorderColor") val highlightBorderColor: String? = null,
@SerializedName("clickOutsideClose") val clickOutsideClose: Boolean? = null,
@SerializedName("placement") val placement: String? = null,
@SerializedName("darkOverlay") val darkOverlay: Boolean? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,11 @@ class FormbricksViewModel : ViewModel() {
jsonObject.addProperty("contactId", UserManager.contactId)
jsonObject.addProperty("isWebEnvironment", false)

val matchedSurvey = environmentDataHolder.data?.data?.surveys?.first { it.id == surveyId }
val project = environmentDataHolder.data?.data?.project

val isMultiLangSurvey =
(environmentDataHolder.data?.data?.surveys?.first { it.id == surveyId }?.languages?.size
(matchedSurvey?.languages?.size
?: 0) > 1

if (isMultiLangSurvey) {
Expand All @@ -139,8 +142,15 @@ class FormbricksViewModel : ViewModel() {
jsonObject.addProperty("languageCode", "default")
}

val hasCustomStyling = environmentDataHolder.data?.data?.surveys?.first { it.id == surveyId }?.styling != null
val enabled = environmentDataHolder.data?.data?.project?.styling?.allowStyleOverwrite ?: false
val hasCustomStyling = matchedSurvey?.styling != null

val placement = matchedSurvey?.projectOverwrites?.placement ?: project?.placement
if (placement != null) jsonObject.addProperty("placement", placement)

val darkOverlay = matchedSurvey?.projectOverwrites?.darkOverlay ?: project?.darkOverlay
if (darkOverlay != null) jsonObject.addProperty("darkOverlay", darkOverlay)

val enabled = project?.styling?.allowStyleOverwrite ?: false
if (hasCustomStyling && enabled) {
environmentDataHolder.getStyling(surveyId)?.let { jsonObject.add("styling", it) }
} else {
Expand Down
Loading