All files / src/components/supportWidget FeedbackForm.tsx

8.33% Statements 1/12
0% Branches 0/4
0% Functions 0/2
8.33% Lines 1/12

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                            3x                                                                                    
import { CreateAction } from '../../form';
import React, { ReactElement, useEffect, useState } from 'react';
import { FeedbackType } from '.';
import { FeedbackDomainName } from '@config/domain';
import { getOrganization, getUserId, getUsername } from '@utils/TokenUtils';
import { Spin } from 'antd';
 
export interface FeedbackFormProps {
  type: FeedbackType;
  zIndex: number;
  onCancelCallback: () => void;
  ipAddress: string;
}
 
const FeedbackForm = (props: FeedbackFormProps): ReactElement => {
  const { type, zIndex, onCancelCallback, ipAddress } = props;
  const [context, setContext] = useState<Record<string, unknown>>();
  const [loading, setLoading] = useState<boolean>(true);
 
  useEffect(() => {
    if (ipAddress === '') {
      return;
    }
    const context = {
      url: window.location.href,
      userAgent: window.navigator.userAgent,
      language: window.navigator.language,
      platform: window.navigator.platform,
      userContext: {
        id: getUserId(),
        username: getUsername(),
        organization: getOrganization(),
      },
      ipAddress,
    };
    setContext(context);
    setLoading(false);
  }, [ipAddress]);
 
  console.log('context', context);
 
  return loading ? (<Spin />) : (
    <CreateAction
      domainName={FeedbackDomainName}
      zIndex={zIndex + 1}
      initShowCreateModal={true}
      queryParameters={{
        type,
        context: JSON.stringify(context, null, 2),
      }}
      onCancelCallback={onCancelCallback}
    />
  );
};
 
export default FeedbackForm;