Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 4x 4x 4x 1x 1x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 2x | import { Alert, Box, styled, useMediaQuery } from "@mui/material";
import Button from "components/Button";
import { Dialog, DialogActions, DialogContent, DialogTitle } from "components/Dialog";
import StyledLink from "components/StyledLink";
import TextBody from "components/TextBody";
import TextField from "components/TextField";
import { useProfileUser } from "features/profile/hooks/useProfileUser";
import { Trans, useTranslation } from "i18n";
import { GLOBAL, PROFILE } from "i18n/namespaces";
import { useRouter } from "next/router";
import { ReferenceType } from "proto/references_pb";
import { useState } from "react";
import { Controller, useForm } from "react-hook-form";
import {
baseRoute,
helpCenterReportContentURL,
leaveReferenceBaseRoute,
referenceStepStrings,
referenceTypeRoute,
} from "routes";
import { indicateDidntMeetup } from "service/references";
import { theme } from "theme";
import { ReferenceStepProps } from "../ReferenceForm";
import ReferenceStepHeader from "./ReferenceStepHeader";
interface IndicateDidntMeetupFormData {
didStay: boolean;
reasonDidntMeetup: string;
}
const StyledForm = styled("form")(({ theme }) => ({
marginBottom: theme.spacing(2),
}));
const StyledTextBody = styled(TextBody)(({ theme }) => ({
"& > .MuiInputBase-root": {
width: "100%",
},
marginTop: theme.spacing(1),
[theme.breakpoints.up("md")]: {
"& > .MuiInputBase-root": {
width: 400,
},
},
}));
const StyledButtonContainer = styled("div")(({ theme }) => ({
display: "flex",
justifyContent: "center",
paddingTop: theme.spacing(1),
}));
const StyledReasonContainer = styled("div")(({ theme }) => ({
display: "flex",
flexDirection: "column",
marginTop: theme.spacing(3),
width: "100%",
}));
const DidStay = ({ referenceData, referenceType, hostRequestId, setReferenceValues }: ReferenceStepProps) => {
const { t } = useTranslation([GLOBAL, PROFILE]);
const user = useProfileUser();
const router = useRouter();
const isMobile = useMediaQuery(theme.breakpoints.down("md"));
const [didSubmitNotStay, setDidSubmitNotStay] = useState(false);
const [isDidNotStayConfirmationDialogOpen, setIsDidNotStayConfirmationDialogOpen] = useState(false);
const {
control,
handleSubmit,
formState: { errors },
setValue,
watch,
} = useForm<IndicateDidntMeetupFormData>();
const { didStay, reasonDidntMeetup } = watch();
const onSubmitDidNotStay = handleSubmit(async () => {
if (!didStay && hostRequestId) {
await indicateDidntMeetup({
hostRequestId,
reasonDidntMeetup: reasonDidntMeetup || "",
});
setReferenceValues({ ...referenceData, didStay: false });
setDidSubmitNotStay(true);
}
});
const handleDidStay = (event: React.MouseEvent) => {
event.preventDefault();
setReferenceValues({ ...referenceData, didStay: true });
setValue("didStay", true);
if (referenceType === referenceTypeRoute[ReferenceType.REFERENCE_TYPE_FRIEND]) {
router.push(`${leaveReferenceBaseRoute}/${referenceType}/${user.userId}/${referenceStepStrings[1]}`);
} else {
router.push(
`${leaveReferenceBaseRoute}/${referenceType}/${user.userId}/${hostRequestId}/${referenceStepStrings[1]}`,
);
}
};
const handleDidNotStayClick = (event: React.MouseEvent) => {
event.preventDefault();
setReferenceValues({ ...referenceData, didStay: false });
setValue("didStay", false);
};
const handleOpenConfirmationDialog = (event: React.MouseEvent) => {
event.preventDefault();
setIsDidNotStayConfirmationDialogOpen(true);
};
const handleCloseConfirmationDialog = () => {
setIsDidNotStayConfirmationDialogOpen(false);
};
Iif (didSubmitNotStay) {
return (
<Box sx={{ display: "flex", flexDirection: "column", alignItems: "center" }}>
<Alert severity="success">{t("profile:leave_reference.didnt_meetup_submit_success")}</Alert>
<Button
variant="contained"
type="submit"
size="large"
sx={{ marginTop: 2 }}
onClick={() => {
router.push(`${baseRoute}`);
}}
>
{t("profile:leave_reference.go_to_dashboard")}
</Button>
</Box>
);
}
return (
<>
<StyledForm>
<ReferenceStepHeader name={user.name} referenceType={referenceType} step="did-stay" />
<StyledButtonContainer>
<Button
variant="outlined"
type="submit"
size="large"
sx={{ marginTop: 2, marginRight: 2 }}
onClick={handleDidNotStayClick}
>
{t("global:no")}
</Button>
<Button variant="contained" type="submit" size="large" sx={{ marginTop: 2 }} onClick={handleDidStay}>
{t("global:yes")}
</Button>
</StyledButtonContainer>
<StyledTextBody sx={{ marginTop: theme.spacing(3) }}>
<Trans i18nKey="profile:leave_reference.did_stay_explanation" components={{ bold: <strong /> }} />
</StyledTextBody>
{didStay === false && (
<StyledReasonContainer>
<Controller
control={control}
name="reasonDidntMeetup"
render={({ field }) => (
<TextField
{...field}
id="reasonDidntMeetup"
label={t("profile:leave_reference.reason_didnt_meetup")}
error={!!errors.reasonDidntMeetup}
helperText={errors.reasonDidntMeetup?.message}
onChange={field.onChange}
value={field.value}
multiline
minRows={5}
sx={{
"& > .MuiInputBase-root": {
width: "100%",
marginTop: theme.spacing(1),
},
}}
/>
)}
/>
<StyledButtonContainer>
<Button fullWidth={isMobile} onClick={handleOpenConfirmationDialog}>
{t("global:submit")}
</Button>
</StyledButtonContainer>
</StyledReasonContainer>
)}
</StyledForm>
<Dialog
aria-labelledby="did-stay--no-dialog-title"
open={isDidNotStayConfirmationDialogOpen}
onClose={handleCloseConfirmationDialog}
>
<DialogTitle id="did-stay--no-dialog-title">
{referenceType === referenceTypeRoute[ReferenceType.REFERENCE_TYPE_HOSTED]
? t("profile:leave_reference.did_stay_confirmation.title_hosted", {
name: user.name,
})
: t("profile:leave_reference.did_stay_confirmation.title_surfed", {
name: user.name,
})}
</DialogTitle>
<DialogContent>
<Trans
i18nKey={
referenceType === referenceTypeRoute[ReferenceType.REFERENCE_TYPE_HOSTED]
? "profile:leave_reference.did_stay_confirmation.message_hosted"
: "profile:leave_reference.did_stay_confirmation.message_surfed"
}
values={{ name: user.name }}
components={{ reportLink: <StyledLink href={helpCenterReportContentURL} target="#" /> }}
/>
</DialogContent>
<DialogActions>
<Button variant="outlined" onClick={handleCloseConfirmationDialog}>
{t("global:cancel")}
</Button>
<Button variant="contained" onClick={onSubmitDidNotStay}>
{referenceType === referenceTypeRoute[ReferenceType.REFERENCE_TYPE_HOSTED]
? t("profile:leave_reference.did_stay_confirmation.confirm_hosted")
: t("profile:leave_reference.did_stay_confirmation.confirm_surfed")}
</Button>
</DialogActions>
</Dialog>
</>
);
};
export default DidStay;
|