Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add external JSX rendering to Vetrina component #373

Merged
merged 7 commits into from
May 18, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion apps/vetrina-staging/.build-size-sha256
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# SHA256 of the content of the build directory.
# This is used for triggering project deployment when there are updated dependecies.
be1d6a49da254740363a4b0785c517318a36979b6f7f8d068e75acbfbaaf93d7
9e9416f3f41961084ec02d2949de68ed736302bc6c54e284f28ae2d8da8a53cb
32 changes: 20 additions & 12 deletions packages/vetrina/src/Vetrina/Vetrina.purs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ type JSProps =
{ onClose :: Nullable (Effect Unit)
, onLogin :: Nullable (Effect Unit)
, products :: Nullable (Array JSProduct)
, unexpectedError :: Nullable JSX
}

type Props =
{ onClose :: Effect Unit
, onLogin :: Effect Unit
, products :: Either Error (Array Product)
{ onClose :: Effect Unit
, onLogin :: Effect Unit
, products :: Either Error (Array Product)
, unexpectedError :: JSX
}

fromJSProps :: JSProps -> Props
Expand All @@ -61,18 +63,19 @@ fromJSProps jsProps =
, not null products -> Right products
| otherwise -> Left productError
Nothing -> Left productError
, unexpectedError : fromMaybe mempty $ toMaybe jsProps.unexpectedError
}

type State =
{ user :: Maybe User
, purchaseState :: PurchaseState
, poller :: Aff.Fiber Unit
, isLoading :: Maybe Spinner.Loading
, accountStatus :: AccountStatus
, logger :: Sentry.Logger
, products :: Array Product
{ user :: Maybe User
, purchaseState :: PurchaseState
, poller :: Aff.Fiber Unit
, isLoading :: Maybe Spinner.Loading
, accountStatus :: AccountStatus
, logger :: Sentry.Logger
, products :: Array Product
, productSelection :: Maybe Product
, paymentMethod :: User.PaymentMethod
, paymentMethod :: User.PaymentMethod
}

type Self = React.Self Props State
Expand All @@ -92,6 +95,7 @@ data PurchaseState
data OrderFailure
= EmailInUse String
| SubscriptionExists
| InitializationError
| FormFieldError (Array NewPurchase.FormInputField)
| AuthenticationError
| ServerError
Expand Down Expand Up @@ -141,7 +145,7 @@ didMount self = do
products <- liftEffect $ case self.props.products of
Right p -> pure p
Left err -> do
self.setState _ { purchaseState = PurchaseFailed $ UnexpectedError "" }
self.setState _ { purchaseState = PurchaseFailed $ InitializationError }
logger.error err
throwError err

Expand Down Expand Up @@ -253,6 +257,10 @@ render self = vetrinaContainer self $
, productSelection: self.state.productSelection
, onLogin: self.props.onLogin
}
ServerError -> self.props.unexpectedError
ae-mo marked this conversation as resolved.
Show resolved Hide resolved
UnexpectedError _ -> self.props.unexpectedError
InitializationError ->
self.props.unexpectedError
_ ->
Purchase.Error.error
{ onRetry: onRetry
Expand Down