-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(review): Satisfaction modal for advanced repository (#1167)
- Loading branch information
1 parent
f3f7a5d
commit 46e0c16
Showing
10 changed files
with
222 additions
and
118 deletions.
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
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
35 changes: 35 additions & 0 deletions
35
packages/slice-machine/components/ReviewModal/ReviewFormSelect.tsx
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { FC } from "react"; | ||
import { FieldProps } from "formik"; | ||
import { Box, Button } from "theme-ui"; | ||
|
||
const ratingSelectable = [1, 2, 3, 4, 5]; | ||
|
||
export const ReviewFormSelect: FC<FieldProps> = (props) => { | ||
const { field, form } = props; | ||
|
||
return ( | ||
<Box sx={{ mb: 3, display: "flex", justifyContent: "space-between" }}> | ||
{ratingSelectable.map((rating, index) => ( | ||
<Button | ||
variant="secondary" | ||
type="button" | ||
key={index} | ||
onClick={() => void form.setFieldValue("rating", rating)} | ||
className={field.value === rating ? "selected" : ""} | ||
sx={{ | ||
"&:not(:last-of-type)": { | ||
mr: 1, | ||
}, | ||
"&.selected": { | ||
backgroundColor: "code.gray", | ||
color: "white", | ||
}, | ||
}} | ||
data-cy={`review-form-score-${rating}`} | ||
> | ||
{rating} | ||
</Button> | ||
))} | ||
</Box> | ||
); | ||
}; |
70 changes: 70 additions & 0 deletions
70
packages/slice-machine/components/ReviewModal/ReviewModal.tsx
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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { FC } from "react"; | ||
import { useSelector } from "react-redux"; | ||
|
||
import { SliceMachineStoreType } from "@src/redux/type"; | ||
import { getLastSyncChange, getUserReview } from "@src/modules/userContext"; | ||
import { selectAllCustomTypes } from "@src/modules/availableCustomTypes"; | ||
import { getLibraries } from "@src/modules/slices"; | ||
import { hasLocal } from "@lib/models/common/ModelData"; | ||
|
||
import { ReviewForm } from "./ReviewForm"; | ||
|
||
export const ReviewModal: FC = () => { | ||
const { userReview, customTypes, libraries, lastSyncChange } = useSelector( | ||
(store: SliceMachineStoreType) => ({ | ||
userReview: getUserReview(store), | ||
customTypes: selectAllCustomTypes(store), | ||
libraries: getLibraries(store), | ||
lastSyncChange: getLastSyncChange(store), | ||
}) | ||
); | ||
|
||
const sliceCount = | ||
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions | ||
libraries && libraries.length | ||
? libraries.reduce((count, lib) => { | ||
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions | ||
if (!lib) return count; | ||
return count + lib.components.length; | ||
}, 0) | ||
: 0; | ||
|
||
const hasSliceWithinCustomType = customTypes.some( | ||
(customType) => | ||
hasLocal(customType) && | ||
customType.local.tabs.some( | ||
(tab) => tab.sliceZone && tab.sliceZone?.value.length > 0 | ||
) | ||
); | ||
|
||
const hasPushedAnHourAgo = Boolean( | ||
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions | ||
lastSyncChange && Date.now() - lastSyncChange >= 3600000 | ||
); | ||
|
||
const isAdvancedRepository = | ||
sliceCount >= 6 && | ||
customTypes.length >= 6 && | ||
hasSliceWithinCustomType && | ||
hasPushedAnHourAgo; | ||
|
||
if (!userReview.advancedRepository && isAdvancedRepository) { | ||
return <ReviewForm reviewType="advancedRepository" />; | ||
} | ||
|
||
const isOnboardingDone = | ||
sliceCount >= 1 && | ||
customTypes.length >= 1 && | ||
hasSliceWithinCustomType && | ||
hasPushedAnHourAgo; | ||
|
||
if ( | ||
!userReview.onboarding && | ||
!userReview.advancedRepository && | ||
isOnboardingDone | ||
) { | ||
return <ReviewForm reviewType="onboarding" />; | ||
} | ||
|
||
return null; | ||
}; |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export { ReviewModal } from "./ReviewModal"; |
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
Oops, something went wrong.