Skip to content

Commit dc8cd9a

Browse files
fix(readme): Init accesstype documentation (#73)
1 parent 4245304 commit dc8cd9a

File tree

1 file changed

+97
-1
lines changed

1 file changed

+97
-1
lines changed

README.md

Lines changed: 97 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ This is a set of components that is to be used to build a Quintype Node App. Thi
3737
* [Marquee for Breaking News](#marquee-for-breaking-news)
3838
* [ReactTable for table story elements](#reacttable-for-table-story-elements)
3939
* [UpdateOnInterval](#UpdateOnInterval)
40+
* [AccessType](#accesstype)
4041

4142
### BreakingNews
4243
This component will automatically fetch breaking news every 30 seconds, and render the provided view.
@@ -609,4 +610,99 @@ The story table element renders a very basic table story element. It can be enha
609610
({data}) => <Component data={data}></Component>
610611
}
611612
</UpdateOnInterval>
612-
```
613+
```
614+
615+
### AccessType
616+
617+
`AccessType` is a generic connected render prop which exposes methods to handle access to stories / assets and initialize accesstype js
618+
619+
Name | arguments | Description
620+
--- | --- | ---
621+
`initAccessType`| -NA- | Initializes accesstype, checks for existance of accesstype before requesting for AT js
622+
`initRazorPayPayment`| `selectedPlan`(object) | Executes accesstype js method to bring forth RP payment gateway
623+
`checkAccess`| `assetId`(string) | Checks if the user has access to the story/asset id passed
624+
`getSubscriptionForUser`| -NA- | Gets the subscriptions of the current logged in user
625+
`accessUpdated`| `accessObject`(object) | Sets the current story access to redux store
626+
`accessIsLoading`| `loading`(boolean) | A boolean which holds true between the request for access of a story and its response
627+
628+
629+
##### Props
630+
631+
Name | type | isRequired
632+
--- | --- | ---
633+
`children`| `func` | yes
634+
`email`| `string` | no
635+
`phone`| `number` | no
636+
`isStaging`| `boolean` | no
637+
`enableAccesstype`| `boolean` | yes
638+
`accessTypeKey`| `string` | yes
639+
640+
641+
###### Notes :
642+
643+
* This component uses AccessType Js internally
644+
* It uses the Access API from subtype for metering, the API works on firebase which uses `thinmint` cookie (set by qlitics) of the user to verify and keep track of visits
645+
* This component only supports Razorpay payment options for now
646+
* It communicates to sketches where routes are in pattern `/api/access/v1/*`
647+
* Metered story has a pingback which is achieved by the use of `navigator.sendBeacon` if available or falls back to fetch, this is needed to update the count of the visited stories for a user
648+
* Access to story/asset is saved on the redux store under the keyword access which holds keys as story asset id and the access returned from the API as its value
649+
* `subscriptions` is the key in the store under which all the subscription groups created for the specified account are maintained
650+
* `paymentOptions` is the key under the store which has all the payment options created for the current AT account
651+
* `selectedPlan` used by `initRazorPayPayment` refers to one of the plan object nested within the subscription groups
652+
653+
```javascript
654+
//access object on store
655+
656+
access : {
657+
'c1f6c0d7-2829-4d31-b673-58728f944f82': {
658+
'data': {
659+
'isLoggedIn':true,
660+
'granted': false
661+
'grantReason': "SUBSCRIBER"
662+
}
663+
}
664+
}
665+
```
666+
667+
668+
###### Usage:
669+
670+
```javascript
671+
import { AccessType } from "@quintype/components";
672+
673+
674+
render() {
675+
return <AccessType
676+
enableAccesstype={enableAccesstype}
677+
isStaging={isStaging}
678+
accessTypeKey={accessTypeKey}
679+
email={email}
680+
phone={phone}
681+
disableMetering={disableMetering}
682+
>
683+
{({ initAccessType, checkAccess, accessUpdated, accessIsLoading }) => (
684+
<div>
685+
<StoryComponent
686+
accessIsLoading={accessIsLoading}
687+
accessUpdated={accessUpdated}
688+
initAccessType={initAccessType}
689+
checkAccess={checkAccess}
690+
{...this.props}
691+
/>
692+
</div>
693+
)}
694+
</AccessType>
695+
}
696+
697+
```
698+
699+
700+
###### Redux notes:
701+
702+
The component dispatches the following actions
703+
704+
* `ACCESS_BEING_LOADED`
705+
* `ACCESS_UPDATED`
706+
* `PAYMENT_OPTIONS_UPDATED`
707+
* `SUBSCRIPTION_GROUP_UPDATED`
708+
* `METER_UPDATED`

0 commit comments

Comments
 (0)