-
Notifications
You must be signed in to change notification settings - Fork 1
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
[feat]: Add support for Key value pair in AccessType #575
Open
shraddha-kesari
wants to merge
8
commits into
master
Choose a base branch
from
key-value-pair-861
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4007274
Add support for key value pair in AT
shraddha-kesari 7e14598
fix lint
shraddha-kesari 0ab370b
Add var to group name
shraddha-kesari f6efb17
Remove classname
shraddha-kesari 74a738e
Add var names
shraddha-kesari 0aa41e1
Add more var names
shraddha-kesari 856d126
PR changes
shraddha-kesari 24ef0c9
Revert back to staging cred
shraddha-kesari File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import React, { useState, useEffect } from "react"; | ||
import { object, func } from "prop-types"; | ||
import get from "lodash/get"; | ||
|
||
import "./group-and-plans.m.css"; | ||
|
||
export const GroupsAndPlansModal = ({ member, setActiveTab, setSelectedPlan, getSubscription }) => { | ||
const [subscriptionsData, setSubscriptionsData] = useState([]); | ||
const [selectedSubscriptions, setSelectedSubscriptions] = useState({}); | ||
const [selectedOption, setSelectedOption] = useState(null); | ||
|
||
useEffect(() => { | ||
getSubscription().then((res) => setSubscriptionsData(res)); | ||
}, []); | ||
|
||
useEffect(() => { | ||
const defaultSelectedOptions = {}; | ||
subscriptionsData.forEach((group, id) => { | ||
subscriptionsData.forEach((group) => { | ||
const firstPlan = get(group, ["subscription_plans", "0"]); | ||
defaultSelectedOptions[group.name] = firstPlan; | ||
}); | ||
|
@@ -26,6 +26,11 @@ export const GroupsAndPlansModal = ({ member, setActiveTab, setSelectedPlan, get | |
member ? setActiveTab("checkout") : setActiveTab("login"); | ||
}; | ||
|
||
const handleOptionClick = (groupName, plan) => { | ||
setSelectedOption(plan); | ||
setSelectedSubscriptions({ ...selectedSubscriptions, [groupName]: plan }); | ||
}; | ||
|
||
return ( | ||
<> | ||
<div styleName="title">Choose A Plan</div> | ||
|
@@ -35,29 +40,59 @@ export const GroupsAndPlansModal = ({ member, setActiveTab, setSelectedPlan, get | |
</p> | ||
<div styleName="groups"> | ||
{subscriptionsData.map((group, id) => { | ||
const renderRichText = (richText) => { | ||
return <div dangerouslySetInnerHTML={{ __html: richText }} />; | ||
}; | ||
const groupName = selectedSubscriptions[group.name]; | ||
const groupDurationLength = groupName && groupName.duration_length; | ||
const groupDurationUnit = groupName && groupName.duration_unit; | ||
return ( | ||
<div key={id} styleName="group-card"> | ||
<div styleName="group-name">{group.name}</div> | ||
<div styleName="plan-name"> | ||
<select | ||
styleName="select-option" | ||
onChange={(e) => | ||
setSelectedSubscriptions({ ...selectedSubscriptions, [group.name]: JSON.parse(e.target.value) }) | ||
} | ||
> | ||
{group.subscription_plans.map((plan, id) => { | ||
return ( | ||
// eslint-disable-next-line react/jsx-key | ||
<option key={id} value={JSON.stringify(plan)}> | ||
{`${plan.duration_length} ${ | ||
plan.duration_length === 1 | ||
? plan.duration_unit.substring(0, plan.duration_unit.length - 1) | ||
: plan.duration_unit | ||
} ${plan.price_cents / 100} ${plan.price_currency}`} | ||
</option> | ||
); | ||
})} | ||
</select> | ||
<div> | ||
{groupName && ( | ||
<div styleName="selected-option" onClick={() => handleOptionClick(group.name, groupName)}> | ||
<span styleName="right-spacer">{groupDurationLength}</span> | ||
<span styleName="right-spacer"> | ||
{groupDurationLength === 1 | ||
? groupDurationUnit.substring(0, groupDurationUnit.length - 1) | ||
: groupDurationUnit} | ||
</span> | ||
<span>{groupName.price_cents / 100}</span> | ||
{groupName.price_currency} | ||
</div> | ||
)} | ||
<div> | ||
{group.subscription_plans.map((plan, index) => { | ||
const durationUnit = plan && plan.duration_unit; | ||
const durationLength = plan && plan.duration_length; | ||
return ( | ||
<> | ||
<div | ||
key={index} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. key shouldn't be index |
||
styleName={`option ${selectedOption === plan ? "option-select" : ""}`} | ||
onClick={() => handleOptionClick(group.name, plan)} | ||
> | ||
<span styleName="right-spacer">{1 + index}.</span> | ||
<span styleName="right-spacer">{durationLength}</span> | ||
<span styleName="right-spacer"> | ||
{durationLength === 1 ? durationUnit.substring(0, durationUnit.length - 1) : durationUnit} | ||
</span> | ||
<span>{plan.price_cents / 100}</span> | ||
<span styleName="right-spacer">{plan.price_currency} </span> | ||
{plan.custom_attributes && | ||
plan.custom_attributes.map((attribute) => ( | ||
<div styleName="left-spacer" key={1}> | ||
{attribute.value && renderRichText(attribute.value)} | ||
</div> | ||
))} | ||
</div> | ||
</> | ||
); | ||
})} | ||
</div> | ||
</div> | ||
</div> | ||
<div styleName="plan-description">{group.description}</div> | ||
<button styleName="subscribe-btn" onClick={() => handlePlanSelection(group.name)}> | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
plan will always be truthy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
destructure to a single line