Skip to content

Commit

Permalink
fix: moved delete all sample data from account settings (#1034)
Browse files Browse the repository at this point in the history
  • Loading branch information
Riddhiagrawal001 authored Jul 22, 2024
1 parent 66e8885 commit be4b048
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/components/ACLDiv.res
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ let make = (
~justifyClass=?,
~tooltipForWidthClass=?,
~dataAttrStr=?,
~height=?,
) => {
<ACLToolTip
access=permission
Expand All @@ -22,6 +23,7 @@ let make = (
?contentAlign
?tooltipWidthClass
?justifyClass
?height
toolTipFor={<AddDataAttributes
attributes=[("data-testid", dataAttrStr->Option.getOr("")->String.toLowerCase)]>
<div className onClick={permission === CommonAuthTypes.Access ? onClick : {_ => ()}}>
Expand Down
1 change: 1 addition & 0 deletions src/components/ACLDiv.resi
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ let make: (
~justifyClass: string=?,
~tooltipForWidthClass: string=?,
~dataAttrStr: string=?,
~height: string=?,
) => React.element
72 changes: 64 additions & 8 deletions src/screens/Order/OrderUIUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ module GenerateSampleDataButton = {
let mixpanelEvent = MixpanelHook.useSendEvent()
let updateDetails = useUpdateMethod()
let showToast = ToastState.useShowToast()
let showPopUp = PopUpState.useShowPopUp()
let {sampleData} = HyperswitchAtom.featureFlagAtom->Recoil.useRecoilValueFromAtom
let userPermissionJson = Recoil.useRecoilValueFromAtom(HyperswitchAtom.userPermissionAtom)

Expand All @@ -74,15 +75,70 @@ module GenerateSampleDataButton = {
}
}

let deleteSampleData = async () => {
try {
let generateSampleDataUrl = getURL(~entityName=GENERATE_SAMPLE_DATA, ~methodType=Delete, ())
let _ = await updateDetails(
generateSampleDataUrl,
Dict.make()->JSON.Encode.object,
Delete,
(),
)
showToast(~message="Sample data deleted successfully", ~toastType=ToastSuccess, ())
getOrdersList()->ignore
} catch {
| _ => ()
}
}

let openPopUpModal = _ =>
showPopUp({
popUpType: (Warning, WithIcon),
heading: "Are you sure?",
description: {
"This action cannot be undone. This will permanently delete all the sample payments and refunds data. To confirm, click the 'Delete All' button below."->React.string
},
handleConfirm: {
text: "Delete All",
onClick: {
_ => {
deleteSampleData()->ignore
}
},
},
handleCancel: {
text: "Cancel",
onClick: {
_ => ()
},
},
})

let rightIconClick = ev => {
ev->ReactEvent.Mouse.stopPropagation
openPopUpModal()
}

<RenderIf condition={sampleData && !previewOnly}>
<ACLButton
access={userPermissionJson.operationsManage}
buttonType={Secondary}
buttonSize={XSmall}
text="Generate Sample Data"
onClick={_ => generateSampleData()->ignore}
leftIcon={CustomIcon(<Icon name="plus" size=13 />)}
/>
<div className="flex items-start">
<ACLButton
access={userPermissionJson.operationsManage}
buttonType={Secondary}
buttonSize={XSmall}
text="Generate Sample Data"
customButtonStyle="!rounded-l-md !rounded-none"
onClick={_ => generateSampleData()->ignore}
leftIcon={CustomIcon(<Icon name="plus" size=13 />)}
/>
<ACLDiv
height="h-fit"
permission={userPermissionJson.operationsManage}
className="bg-jp-gray-button_gray text-jp-gray-900 text-opacity-75 hover:bg-jp-gray-secondary_hover hover:text-jp-gray-890 focus:outline-none items-center border border-border_gray cursor-pointer p-2.5 overflow-hidden text-jp-gray-950 hover:text-black
border flex items-center justify-center rounded-r-md"
onClick={ev => rightIconClick(ev)}>
<Icon name="delete" size=16 customWidth="14" className="scale-125" />
</ACLDiv>
</div>
</RenderIf>
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/screens/Order/Orders.res
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ let make = (~previewOnly=false) => {
<RenderIf condition={!previewOnly}>
<div className="flex-1"> {filtersUI} </div>
</RenderIf>
<div className="flex justify-end gap-3">
<div className="flex justify-end gap-3 items-start">
<RenderIf condition={generateReport && orderData->Array.length > 0}>
<GenerateReport entityName={PAYMENT_REPORT} />
</RenderIf>
Expand Down

0 comments on commit be4b048

Please sign in to comment.