Guest User

Untitled

a guest
Jan 14th, 2024
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. "use client";
  2. import apiClient from "@/apiclient/ApiClient";
  3. import { IUser } from "@/app/api/nextauth";
  4. import {
  5.   Autocomplete,
  6.   Box,
  7.   Button,
  8.   FormControlLabel,
  9.   IconButton,
  10.   MenuItem,
  11.   Switch,
  12.   TextField,
  13.   Tooltip,
  14.   Typography,
  15. } from "@mui/material";
  16. import { signOut } from "next-auth/react";
  17. import { useRouter } from "next/navigation";
  18. import { useState } from "react";
  19. import { getDashboardUrl } from "../../components/GetDashboardUrl";
  20. import {
  21.   getDisabilitiesOptions,
  22.   getDisabilitiesValue,
  23.   getStandardInterviewOptions,
  24.   getStandardPreferredApproachOptions,
  25. } from "@/app/utility/profile_utility";
  26. import InfoIcon from "@mui/icons-material/Info";
  27. import { DisabilityDto } from "@/apiclient/endpoints/panel/profile";
  28.  
  29. const PanelProfileData = ({ session }: { session: any }) => {
  30.   const router = useRouter();
  31.   const [profilePreferences, setProfileData] = useState({
  32.     preferredInterviewType: "",
  33.     preferredApproachType: "",
  34.     commercialApproaches: false,
  35.   });
  36.  
  37.   const [profileDisabilities, setProfileDisabilities] = useState<string[]>([]);
  38.  
  39.   const navigateTo = (path: string) => {
  40.     router.push(path);
  41.   };
  42.  
  43.   const handleProfileSetup = async () => {
  44.     try {
  45.       const response =
  46.         await apiClient.panel.profile.addPreferenceData(profilePreferences);
  47.       console.log(response);
  48.  
  49.       navigateTo(getDashboardUrl(session.data?.user));
  50.     } catch (error) {
  51.       if (error instanceof Error) {
  52.         console.log(error.message);
  53.       }
  54.     }
  55.   };
  56.  
  57.   return (
  58.     <Box
  59.       sx={{
  60.         display: "flex",
  61.         flexDirection: "column",
  62.         alignItems: "center",
  63.         bgcolor: "background.paper",
  64.         padding: 3,
  65.         boxShadow: 10,
  66.         borderRadius: 3,
  67.       }}
  68.     >
  69.       <Typography component="h1" variant="h5">
  70.         Vul nu uw voorkeuren in!
  71.       </Typography>
  72.       <TextField
  73.         label="Voorkeur Interview Type"
  74.         select
  75.         variant="outlined"
  76.         margin="normal"
  77.         fullWidth
  78.         value={profilePreferences.preferredInterviewType}
  79.         onChange={(e) =>
  80.           setProfileData({
  81.             ...profilePreferences,
  82.             preferredInterviewType: e.target.value,
  83.           })
  84.         }
  85.       >
  86.         {getStandardInterviewOptions().map((option) => (
  87.           <MenuItem key={option} value={option}>
  88.             {option}
  89.           </MenuItem>
  90.         ))}
  91.       </TextField>
  92.       <TextField
  93.         label="Voorkeur Benaderings Type"
  94.         select
  95.         variant="outlined"
  96.         margin="normal"
  97.         fullWidth
  98.         value={profilePreferences.preferredApproachType}
  99.         onChange={(e) =>
  100.           setProfileData({
  101.             ...profilePreferences,
  102.             preferredApproachType: e.target.value,
  103.           })
  104.         }
  105.       >
  106.         {getStandardPreferredApproachOptions().map((option) => (
  107.           <MenuItem key={option} value={option}>
  108.             {option}
  109.           </MenuItem>
  110.         ))}
  111.       </TextField>
  112.  
  113.       <Typography variant="h6" paragraph>
  114.         Commerciële benaderingen
  115.         <Tooltip title="Hiermee geeft u aan of dat u door commerciale bedrijven wil benaderd worden.">
  116.           <IconButton
  117.             size="small"
  118.             style={{ marginLeft: "5px" }}
  119.             color="primary"
  120.             aria-label="info"
  121.           >
  122.             <InfoIcon fontSize="inherit" />
  123.           </IconButton>
  124.         </Tooltip>
  125.       </Typography>
  126.       <FormControlLabel
  127.         control={
  128.           <Switch
  129.             checked={profilePreferences?.commercialApproaches ?? false}
  130.             onChange={(e) =>
  131.               setProfileData({
  132.                 ...profilePreferences,
  133.                 commercialApproaches: !profilePreferences.commercialApproaches,
  134.               })
  135.             }
  136.             color="primary"
  137.           />
  138.         }
  139.         label={profilePreferences?.commercialApproaches ? "Ja" : "Nee"}
  140.       />
  141.  
  142.       <Typography variant="h6" paragraph>
  143.         Beperkingen
  144.       </Typography>
  145.       <Autocomplete
  146.         multiple
  147.         id="disabilities"
  148.         options={getDisabilitiesOptions()}
  149.         value={profileDisabilities}
  150.         onChange={(_, selectedDisabilities: string[]) => {
  151.           setProfileDisabilities(selectedDisabilities);
  152.         }}
  153.         disableCloseOnSelect
  154.         renderInput={(params) => (
  155.           <TextField {...params} label="Beperkingen" margin="normal" />
  156.         )}
  157.       />
  158.  
  159.  
  160.       <Button
  161.         type="submit"
  162.         fullWidth
  163.         variant="contained"
  164.         sx={{ mt: 3 }}
  165.         onClick={handleProfileSetup}
  166.       >
  167.         Setup Profiel
  168.       </Button>
  169.       <Button
  170.         type="submit"
  171.         fullWidth
  172.         variant="contained"
  173.         color="error"
  174.         sx={{ mt: 3, mb: 2 }}
  175.         onClick={() => signOut({ redirect: true, callbackUrl: "/" })}
  176.       >
  177.         Log uit
  178.       </Button>
  179.     </Box>
  180.   );
  181. };
  182.  
  183. export default PanelProfileData;
  184.  
Advertisement
Add Comment
Please, Sign In to add comment