-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(feedbak): add initial new modal * feat(feedbackmodal): shift ui * feat(rating): add new componentn * refactor(feedbackmodal): update to use new component * chore(feedbackmodal): update ui * feat(types): add types * feat(logincontext): add usertype * feat(feedbackmodal): submit to be * docs(usefeedbackdisclosure): update doc
- Loading branch information
Showing
10 changed files
with
254 additions
and
52 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { | ||
Button as ChakraButton, | ||
useMultiStyleConfig, | ||
chakra, | ||
Text, | ||
Flex, | ||
Box, | ||
Spacer, | ||
} from "@chakra-ui/react" | ||
import { PropsWithChildren } from "react" | ||
|
||
const RATING_SCALE = 11 | ||
|
||
interface RatingButtonProps { | ||
onClick: () => void | ||
isActive: boolean | ||
} | ||
const RatingButton = ({ | ||
onClick, | ||
isActive, | ||
children, | ||
}: PropsWithChildren<RatingButtonProps>) => { | ||
const styles = useMultiStyleConfig("Rating") | ||
const paginationStyles = useMultiStyleConfig("Pagination") | ||
|
||
return ( | ||
<> | ||
<ChakraButton | ||
variant="unstyled" | ||
sx={{ | ||
// NOTE: We need to use the pagination styles | ||
// because the figma uses the pagination button for rating... | ||
...paginationStyles.button, | ||
...styles.button, | ||
}} | ||
onClick={onClick} | ||
isActive={isActive} | ||
> | ||
{children} | ||
</ChakraButton> | ||
</> | ||
) | ||
} | ||
|
||
export interface RatingProps { | ||
onClick: (idx: number) => void | ||
activeIdx: number | ||
} | ||
|
||
export const Rating = ({ onClick, activeIdx }: RatingProps) => { | ||
const styles = useMultiStyleConfig("Rating") | ||
|
||
return ( | ||
<Box> | ||
<chakra.ul __css={styles.container}> | ||
{Array(RATING_SCALE) | ||
.fill(null) | ||
.map((_, idx) => { | ||
return ( | ||
<chakra.li> | ||
<RatingButton | ||
onClick={() => onClick(idx)} | ||
isActive={activeIdx === idx} | ||
> | ||
{idx} | ||
</RatingButton> | ||
</chakra.li> | ||
) | ||
})} | ||
</chakra.ul> | ||
<Flex w="full"> | ||
<Text textStyle="caption-1">Not satisfied</Text> | ||
<Spacer /> | ||
<Text textStyle="caption-1">Very satisfied</Text> | ||
</Flex> | ||
</Box> | ||
) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { AxiosError } from "axios" | ||
import { useMutation, UseMutationResult } from "react-query" | ||
|
||
import * as FeedbackService from "services/FeedbackService" | ||
|
||
import { FeedbackDto } from "types/feedback" | ||
import { useSuccessToast } from "utils" | ||
|
||
export const useSubmitFeedback = (): UseMutationResult< | ||
void, | ||
AxiosError, | ||
FeedbackDto | ||
> => { | ||
const successToast = useSuccessToast() | ||
return useMutation<void, AxiosError, FeedbackDto>( | ||
async (userFeedback) => { | ||
FeedbackService.submitFeedback(userFeedback) | ||
}, | ||
{ | ||
onSuccess: () => { | ||
successToast({ | ||
id: "submit-feedback-success", | ||
description: "Thanks for your feedback!", | ||
}) | ||
}, | ||
} | ||
) | ||
} |
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,8 @@ | ||
import { FeedbackDto } from "types/feedback" | ||
|
||
import { apiService } from "./ApiService" | ||
|
||
export const submitFeedback = (userFeedback: FeedbackDto) => { | ||
const endpoint = "/metrics/feedback" | ||
return apiService.post(endpoint, userFeedback) | ||
} |
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,45 @@ | ||
import { createMultiStyleConfigHelpers } from "@chakra-ui/react" | ||
import { anatomy } from "@chakra-ui/theme-tools" | ||
|
||
import { textStyles } from "theme/textStyles" | ||
|
||
const parts = anatomy("rating").parts("button", "container") | ||
|
||
const { | ||
definePartsStyle, | ||
defineMultiStyleConfig, | ||
} = createMultiStyleConfigHelpers(parts.keys) | ||
|
||
const baseStyle = definePartsStyle({ | ||
container: { | ||
display: "flex", | ||
flexFlow: "row nowrap", | ||
listStyleType: "none", | ||
alignItems: "flex-start", | ||
gap: "1.5rem", | ||
w: "full", | ||
alignSelf: "center", | ||
px: "1.16rem", | ||
py: "0.5rem", | ||
}, | ||
button: { | ||
...textStyles["subhead-2"], | ||
minH: "auto", | ||
minW: "auto", | ||
_active: { | ||
bg: "interaction.support.selected", | ||
color: "base.content.inverse", | ||
_hover: { | ||
bg: "interaction.support.selected", | ||
}, | ||
_disabled: { | ||
bg: "interaction.support.disabled", | ||
color: "interaction.support.disabled-content", | ||
}, | ||
}, | ||
}, | ||
}) | ||
|
||
export const Rating = defineMultiStyleConfig({ | ||
baseStyle, | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { UserType } from "./user" | ||
|
||
export interface FeedbackDto { | ||
rating: number | ||
feedback: string | ||
email: string | ||
userType: UserType | ||
} |
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