Skip to content

Commit

Permalink
Fix survey URL generation
Browse files Browse the repository at this point in the history
  • Loading branch information
henrycatalinismith committed May 24, 2024
1 parent 0309345 commit 0265ec7
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/features/surveys/components/SurveyURLCard.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { OpenInNew } from '@mui/icons-material';
import { useMemo } from 'react';
import { Box, Link, useTheme } from '@mui/material';

import ZUICard from 'zui/ZUICard';
import ZUITextfieldToClipboard from 'zui/ZUITextfieldToClipboard';
import { Msg, useMessages } from 'core/i18n';

import messageIds from '../l10n/messageIds';
import useSurvey from '../hooks/useSurvey';

interface SurveyURLCardProps {
isOpen: boolean;
Expand All @@ -14,8 +16,16 @@ interface SurveyURLCardProps {
}

const SurveyURLCard = ({ isOpen, orgId, surveyId }: SurveyURLCardProps) => {
const survey = useSurvey(parseInt(orgId), parseInt(surveyId));
const messages = useMessages(messageIds);
const theme = useTheme();
const surveyUrl = useMemo(
() =>
survey.data
? `${location.protocol}//${location.host}/o/${survey.data.organization.id}/surveys/${surveyId}`
: '',
[survey.data, surveyId]
);
return (
<ZUICard
header={isOpen ? messages.urlCard.open() : messages.urlCard.preview()}
Expand All @@ -36,10 +46,8 @@ const SurveyURLCard = ({ isOpen, orgId, surveyId }: SurveyURLCardProps) => {
}
>
<Box display="flex" paddingBottom={2}>
<ZUITextfieldToClipboard
copyText={`${location.protocol}//${location.host}/o/${orgId}/surveys/${surveyId}`}
>
{`${location.protocol}//${location.host}/o/${orgId}/surveys/${surveyId}`}
<ZUITextfieldToClipboard copyText={surveyUrl}>
{surveyUrl}
</ZUITextfieldToClipboard>
</Box>
<Link
Expand Down

0 comments on commit 0265ec7

Please # to comment.