Skip to content

Commit

Permalink
Merge pull request #162 from picortex/master-dev
Browse files Browse the repository at this point in the history
Master dev
  • Loading branch information
andylamax authored Oct 22, 2021
2 parents c8a9243 + 1dbabb6 commit 10573f7
Show file tree
Hide file tree
Showing 85 changed files with 847 additions and 157 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# 0.0.31

## PiMonitor Client SDK Core

- [[PM124]](https://github.com/picortex/bitframe/issues/124) Removed onUserLoggedIn method from SignInViewModel
- [[PM141]](https://github.com/picortex/bitframe/issues/141) Created a Register business form
- [[PM140]](https://github.com/picortex/bitframe/issues/140) Make the register business form be invitational
- [[PM023]](https://github.com/picortex/bitframe/issues/23) Register a business
- [[PM017]](https://github.com/picortex/bitframe/issues/17) A Monitor can create a business, in his scope

# 0.0.30

## PiMonitor Client SDK Core
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import kotlin.js.JsExport

abstract class SignInService(
open val bus: EventBus,
open val config: ServiceConfig
protected open val config: ServiceConfig
) {
val session: Live<Session> = Live(Session.Unknown)
val currentSession get() = session.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ import kotlin.jvm.JvmSynthetic
class TestClientConfiguration @JvmOverloads private constructor(
override val appId: String,
/** The time (in milliseconds) a client would take to simulate fake activity */
val simulationTime: Int = DEFAULT_SIMULATION_TIME,
val simulationTime: Long = DEFAULT_SIMULATION_TIME,
override val scope: CoroutineScope,
) : ClientConfiguration(appId, scope) {
companion object {
const val DEFAULT_SIMULATION_TIME = 0
const val DEFAULT_SIMULATION_TIME: Long = 0
private val cachedConfigs = mutableMapOf<String, TestClientConfiguration>()

@JvmSynthetic
operator fun invoke(
appId: String,
simulationTime: Int = DEFAULT_SIMULATION_TIME,
simulationTime: Long = DEFAULT_SIMULATION_TIME,
scope: CoroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
): TestClientConfiguration = cachedConfigs.getOrPut(appId) {
TestClientConfiguration(appId, simulationTime, scope)
Expand All @@ -33,7 +33,7 @@ class TestClientConfiguration @JvmOverloads private constructor(
@JvmOverloads
fun of(
appId: String,
simulationTime: Int = DEFAULT_SIMULATION_TIME,
simulationTime: Long = DEFAULT_SIMULATION_TIME,
scope: CoroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
) = invoke(appId, simulationTime, scope)

Expand Down
8 changes: 4 additions & 4 deletions bitframe-client/ui/react/src/main/kotlin/bitframe/Bitframe.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ private fun defaultRenderers(

fun RBuilder.Bitframe(
client: BitframeService,
routeRenderers: Map<String, Renderer> = mapOf(),
moduleRenderers: Map<String, Renderer> = mapOf(),
pages: Map<String, Renderer> = mapOf(),
modules: Map<String, Renderer> = mapOf(),
version: String
) = browserRouter {
val allRouteRenderers = routeRenderers.toMutableMap().apply {
putAll(defaultRenderers(client, moduleRenderers, version))
val allRouteRenderers = pages.toMutableMap().apply {
putAll(defaultRenderers(client, modules, version))
}
switch {
for ((path, renderer) in allRouteRenderers) route(path, render = renderer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ private external interface SignInPageProps : Props {
}

private val SignInPage = fc<SignInPageProps> { props ->
val viewModel = props.scope.viewModel
val scope = props.scope
val viewModel = scope.viewModel
val useSignInEvent = scope.useSignInEvent
val ui = useViewModelState(viewModel)
useEffectOnce {
viewModel.onUserLoggedIn { _, _ ->
props.history.push("/panel")
}
useSignInEvent {
props.history.push("/panel")
}

styledDiv {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
@file:JsExport

package bitframe.authentication.signin

import bitframe.authentication.spaces.Space
import bitframe.authentication.users.User
import bitframe.presenters.feedbacks.FormFeedback.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.delay
Expand All @@ -20,8 +16,6 @@ class SignInViewModel(
private val service: SignInService
) : ViewModel<SignInIntent, SignInState>(SignInState(SignInFormFields(), null)) {

private var loginListener: ((User, Space) -> Unit)? = null

private val recoveryTime = 3000

val console = logger()
Expand All @@ -30,10 +24,6 @@ class SignInViewModel(
is SignInIntent.Submit -> signIn(i)
}

fun onUserLoggedIn(listener: (User, Space) -> Unit) {
loginListener = listener
}

private fun CoroutineScope.signIn(i: SignInIntent.Submit) = launch {
val state = ui.value.copy(status = Loading("Signing you in, please wait . . ."))
flow {
Expand All @@ -42,12 +32,8 @@ class SignInViewModel(
if (conundrum.spaces.size > 1) {
console.warn("User has more than one Space, ")
emit(state.copy(status = Success("Logged in successfully")))
loginListener?.invoke(conundrum.user, conundrum.spaces.first())
} else {
val user = conundrum.user
val account = conundrum.spaces.first()
emit(state.copy(status = Success("Logged in successfully")))
loginListener?.invoke(user, account)
}
}.catch {
emit(state.copy(status = Failure(it)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@

package bitframe.authentication.signin.exports

import bitframe.authentication.signin.Session
import bitframe.authentication.signin.SignInIntent
import bitframe.authentication.signin.SignInService
import bitframe.authentication.signin.SignInViewModel
import bitframe.authentication.signin.*
import useEventHandler
import viewmodel.ViewModel

class SignInScope(service: SignInService) {

val viewModel by lazy { SignInViewModel(service) }
val viewModel: ViewModel<SignInIntent, SignInState> by lazy { SignInViewModel(service) }

val submit = { cred: SignInCredentials ->
viewModel.post(SignInIntent.Submit(cred.toSignInCredentials()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import kotlinx.coroutines.SupervisorJob
import kotlin.jvm.JvmField

open class InMemoryDaoConfig(
val simulationTime: Int,
val simulationTime: Long,
override val scope: CoroutineScope = CoroutineScope(SupervisorJob())
) : DaoConfig {
companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@file:JsExport

package bitframe.presenters.fields

import kotlinx.serialization.Serializable
import kotlin.js.JsExport

@Serializable
data class BooleanInputField(
val label: String,
var value: Boolean? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ import kotlin.js.JsExport
import kotlin.js.JsName

data class DropDownInputField(
val options: List<Option>
@JsName("_options") val options: List<Option>
) {
@JsName("from")
constructor(vararg options: Option) : this(options.toList())

val items get() = options.toTypedArray()

val selected get() = options.firstOrNull { it.selected }

data class Option(
val label: String, val value: String = label, val selected: Boolean = false
val label: String,
val value: String = label,
val selected: Boolean = false
)
}
4 changes: 2 additions & 2 deletions buildSrc/src/main/kotlin/versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ object vers {
}

object bitframe {
val current = "0.0.30"
val previous = "0.0.29"
val current = "0.0.31"
val previous = "0.0.30"
}

object asoft {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@ import kotlinx.extensions.onDesktop
import kotlinx.extensions.onMobile
import kotlinx.extensions.text
import kotlinx.html.InputType
import logging.logger
import pimonitor.PiMonitorService
import pimonitor.authentication.signup.exports.SignUpScope
import pimonitor.monitors.SignUpParams
import react.Props
import react.RBuilder
import react.dom.p
import react.fc
import react.router.dom.useHistory
import react.router.dom.withRouter
import react.useEffectOnce
import reakt.*
import styled.css
import styled.styledH2
Expand Down Expand Up @@ -55,11 +52,12 @@ private val SignUp = fc<SignUpProps> { props ->

DropDown(
name = "registrationType",
value = state.select.options.first { it.selected }.value,
value = state.select.selected?.value,
options = state.select.options.map { it.value },
onChange = {
console.log(it)
when (it) {
"Register as Business" -> scope.registerAsBusiness()
"" -> scope.registerAsBusiness()
"Register as Individual" -> scope.registerAsIndividual()
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package pimonitor.evaluation.business

import pimonitor.PiMonitorService
import pimonitor.evaluation.business.exports.CreateBusinessScope
import pimonitor.evaluation.business.forms.CreateBusinessState.*
import react.Props
import react.RBuilder
import react.fc
import react.useEffectOnce
import reakt.ErrorBox
import reakt.LoadingBox
import reakt.SuccessBox
import useViewModelState
import pimonitor.evaluation.business.forms.CreateBusinessIntent as Intent

private external interface AddBusinessProps : Props {
var uid: String?
var scope: CreateBusinessScope
}

private val AddBusiness = fc<AddBusinessProps> { props ->
val scope = props.scope
val vm = scope.viewModel
useEffectOnce { scope.showForm(props.uid) }
when (val state = useViewModelState(vm)) {
is Loading -> LoadingBox(state.message)
is Form -> CreateBusinessForm(
state = state,
onSubmit = { vm.post(Intent.SubmitForm(it)) }
)
is Success -> SuccessBox(state.message)
is Failure -> ErrorBox(state.cause)
}
}

internal fun RBuilder.AddBusiness(service: PiMonitorService, uid: String? = null) = child(AddBusiness) {
attrs.scope = CreateBusinessScope(service)
attrs.uid = uid
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ package pimonitor.evaluation.business
import kotlinx.css.JustifyContent
import kotlinx.css.justifyContent
import pimonitor.PiMonitorService
import pimonitor.evaluation.business.exports.BusinessesScope
import react.Props
import react.RBuilder
import react.fc
import react.router.dom.routeLink
import react.useEffectOnce
import reakt.ContainedButton
import reakt.FlexBox
import reakt.LoadingBox
import reakt.SuccessBox
import reakt.*
import styled.css
import styled.styledDiv
import useViewModelState
Expand All @@ -22,24 +21,29 @@ private external interface BusinessContainerProps : Props {
private val BusinessContainer = fc<BusinessContainerProps> { props ->
val scope = props.scope
val viewModel = scope.viewModel
useEffectOnce { scope.loadBusiness() }
val loadBusinesses = scope.loadBusinesses
val useBusinessAddedEvent = scope.useBusinessAddedEvent
val monitor = scope.service.monitors.currentMonitorOrNull
useBusinessAddedEvent { loadBusinesses() }
useEffectOnce { loadBusinesses() }
when (val state = useViewModelState(viewModel)) {
is BusinessesState.Loading -> LoadingBox(state.message)
is BusinessesState.Businesses -> styledDiv {
FlexBox {
css { justifyContent = JustifyContent.flexEnd }
ContainedButton("Create") { viewModel.post(BusinessesIntent.ShowBusinessForm) }
val link = "/invite/${monitor?.uid}"
routeLink(to = link) { +link }
}
if (state.data.isEmpty()) EmptyBusiness()
else BusinessList(state.data)
}
is BusinessesState.BusinessForm -> styledDiv {
+"Creating form, just wait and see"
}
is BusinessesState.BusinessForm -> AddBusiness(scope.service)
is BusinessesState.Success -> SuccessBox(state.message)
is BusinessesState.Failure -> ErrorBox(state.cause)
}
}

fun RBuilder.BusinessContainer(service: PiMonitorService) = child(BusinessContainer) {
attrs.scope = BusinessesScope(service.businesses)
attrs.scope = BusinessesScope(service)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ internal fun RBuilder.BusinessList(
data,
columns = listOf(
Column("name") { it.name },
Column("email") { it.contacts.first().email.value },
Column("contact") { it.contacts.first().name },
Column("email") { it.contacts.first().email.value },
RenderColumn("actions") {
Grid(cols = "1fr 1fr") {
ContainedButton("View") {}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package pimonitor.evaluation.business

import bitframe.components.TextInput
import kotlinx.css.*
import kotlinx.extensions.onDesktop
import kotlinx.extensions.onMobile
import kotlinx.extensions.text
import pimonitor.evaluation.business.forms.CreateBusinessState
import pimonitor.monitored.CreateMonitoredBusinessParams
import react.RBuilder
import reakt.ContainedButton
import reakt.FlexBox
import reakt.Form
import reakt.centerContent
import styled.css
import styled.styledDiv
import styled.styledH2
import theme.clazz

internal fun RBuilder.CreateBusinessForm(
state: CreateBusinessState.Form,
onSubmit: (params: CreateMonitoredBusinessParams) -> Unit
) = FlexBox { theme ->
css {
centerContent()
onMobile { padding(horizontal = 1.em) }
onDesktop { padding(horizontal = 20.pct) }
}

val fields = state.fields
Form {
fields.inviterIntroduction?.let {
styledDiv { +it }
}
styledH2 {
css { +theme.text.h2.clazz }
+fields.title
}
TextInput("businessName", fields.businessName)
TextInput("contactName", fields.contactName)
TextInput("contactEmail", fields.contactEmail)
ContainedButton(fields.submitButton.text)
} onSubmit {
val businessName by text()
val contactName by text()
val contactEmail by text()

val params = CreateMonitoredBusinessParams(businessName, contactName, contactEmail)
onSubmit(params)
}
}
Loading

0 comments on commit 10573f7

Please sign in to comment.