Skip to content

Commit

Permalink
feat: edit rule auto fill done
Browse files Browse the repository at this point in the history
  • Loading branch information
MdTeach committed Oct 5, 2023
1 parent 0c900f0 commit a4aea50
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 11 deletions.
56 changes: 53 additions & 3 deletions packages/uiweb/src/lib/components/chat/CreateGroup/AddCriteria.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
TypeKeys,
ReadonlyInputType,
} from '../types';
import { Data, Rule } from './Type';
import { Data, GuildData, PushData, Rule } from './Type';


const AddCriteria = ({
Expand Down Expand Up @@ -266,11 +266,16 @@ const AddCriteria = ({
const verifyAndDoNext = ()=>{

const _type = dropdownTypeValues[selectedTypeValue].value as 'PUSH' | 'GUILD'

const subCategory = getSelectedSubCategoryValue() as "owner" | "holder"
const category:string = _type === "PUSH" ? (dropdownCategoryValues[_type] as DropdownValueType[])[
selectedCategoryValue
].value || CATEGORY.ERC20 : "ROLES"

let subCategory = "DEFAULT"
if(_type === "PUSH"){
if(category === CATEGORY.ERC20 || category === CATEGORY.ERC721){
subCategory = tokenCategoryValues[selectedSubCategoryValue].value
}
}

const getData = (type:string, category:string):Data=>{
if(type === "PUSH"){
Expand Down Expand Up @@ -319,11 +324,56 @@ const AddCriteria = ({

}

// Autofill the form for the update
useEffect(()=>{
if(entryCriteria.isUpdateCriteriaEnabled()){
//Load the states
const oldValue = entryCriteria.entryOptionsDataArray[entryCriteria.entryOptionsDataArrayUpdate][entryCriteria.updateCriteriaIdx]

if(oldValue.type === 'PUSH'){

// category
setSelectedCategoryValue(
(dropdownCategoryValues.PUSH as DropdownValueType[]).findIndex(obj => obj.value === oldValue.category)
)

const pushData = oldValue.data as PushData

// sub category
if(oldValue.category === CATEGORY.ERC20 || oldValue.category === CATEGORY.ERC721){
setSelectedSubCategoryValue(
tokenCategoryValues.findIndex(obj => obj.value === oldValue.subcategory)
)

const contractAndChain:string[] = (pushData.contract || "eip155:1:0x").split(':')
setSelectedChainValue(
dropdownChainsValues.findIndex(
obj => obj.value === contractAndChain[0]+":"+contractAndChain[1]
)
)
setContract(contractAndChain.length === 3 ? contractAndChain[2]: "")
setQuantity({value:pushData.amount || 0, range:0})
}else if(oldValue.category === CATEGORY.INVITE){
setInviteCheckboxes({
admin:pushData.inviterRoles === "ADMIN",
owner:pushData.inviterRoles === "OWNER",
})
}else{
// invite
setUrl(pushData.url || "")
}
}else{
// guild condition
setGuildId((oldValue.data as GuildData).id)
setSpecificRoleId((oldValue.data as GuildData).role)
setGuildComparison((oldValue.data as GuildData).comparison)
}

setSelectedTypeValue(
dropdownTypeValues.findIndex(obj => obj.value === oldValue.type)
)


// TODO: reverse the form fill
}
},[0])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,11 @@ export const CreateGroupModal: React.FC<CreateGroupModalProps> = ({
// reset update rules
if(activeComponent === 2){
entryCriteria.selectEntryOptionsDataArrayForUpdate(-1)
entryCriteria.setSelectedRule([])
}else if(activeComponent === 3){
entryCriteria.setUpdateCriteriaIdx(-1)
}
},[activeComponent,entryCriteria])
},[activeComponent])

const [groupInputDetails, setGroupInputDetails] = useState<GroupInputDetailsType>({
groupName:'',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,13 @@ const AddConditionSection = ({
/>

<Button
onClick={handleNext}
onClick={()=>{
if(handleNext){
criteriaState.setSelectedRule([])
criteriaState.setSelectedCriteria(-1)
handleNext()
}
}}
customStyle={{
color: `${theme.backgroundColor?.buttonBackground}`,
fontSize: '15px',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ export const DefineCondtion = ({
entryCriteria.entryOptionTypeArray[entryCriteria.entryOptionsDataArrayUpdate]
)

entryCriteria.setSelectedRule([
...entryCriteria.entryOptionsDataArray[entryCriteria.entryOptionsDataArrayUpdate]
])
if(entryCriteria.selectedRules.length === 0){
entryCriteria.setSelectedRule([
...entryCriteria.entryOptionsDataArray[entryCriteria.entryOptionsDataArrayUpdate],
])
}
}
},[0])

Expand Down
5 changes: 3 additions & 2 deletions packages/uiweb/src/lib/components/chat/CreateGroup/Type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface Rule {
type: 'PUSH' | 'GUILD';
// category: 'ERC20' | 'ERC721';
category: string;
subcategory: 'holder' | 'owner' | 'DEFAULT';
subcategory:string;
data: Data;
}

Expand Down Expand Up @@ -143,7 +143,8 @@ export const useCriteriaState = ():CriteriaStateType=>{
if (selectedCriteria === -1){
setSelectedCriteria(entryOptionTypeArray.length)
}
setSelectedRule((prev)=>[...prev,newRule])

setSelectedRule(prev =>[...prev,newRule])
}

const deleteRule = (idx:number)=>{
Expand Down
2 changes: 1 addition & 1 deletion packages/uiweb/src/lib/components/chat/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const INVITE_CHECKBOX_LABEL: { owner: string; admin: string } = {
value: 'all',
},
{
heading: 'ALL',
heading: 'ANY',
value: 'any',
},
{
Expand Down

0 comments on commit a4aea50

Please sign in to comment.