Skip to content

Commit

Permalink
Merge pull request #45 from Codemarket2/vivekt
Browse files Browse the repository at this point in the history
workflow relationship
  • Loading branch information
appdatasoft authored Mar 11, 2022
2 parents 2355e67 + 5e35724 commit d797699
Show file tree
Hide file tree
Showing 14 changed files with 124 additions and 71 deletions.
29 changes: 15 additions & 14 deletions packages/shared/graphql/mutation/response.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
import { gql } from '@apollo/client';

export const CREATE_RESPONSE = gql`
mutation MyMutation($formId: ID!, $parentId: ID, $values: [FieldValue2Input], $options: AWSJSON) {
createResponse(formId: $formId, parentId: $parentId, values: $values, options: $options) {
mutation MyMutation(
$formId: ID!
$parentId: ID
$responseId: ID
$values: [FieldValue2Input]
$options: AWSJSON
) {
createResponse(
formId: $formId
parentId: $parentId
responseId: $responseId
values: $values
options: $options
) {
_id
formId
count
parentId {
_id
title
}
responseId
values {
_id
field
Expand Down Expand Up @@ -79,18 +92,6 @@ export const UPDATE_RESPONSE = gql`
}
`;

export const UPDATE_RESPONSE_PARENTID = gql`
mutation MyMutation($_id: ID!, $parentId: [ID]) {
updateResponse(_id: $_id, parentId: $parentId) {
_id
parentId {
_id
title
}
}
}
`;

export const DELETE_RESPONSE = gql`
mutation MyMutation($_id: ID!) {
deleteResponse(_id: $_id)
Expand Down
6 changes: 6 additions & 0 deletions packages/shared/graphql/query/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const GET_RESPONSE = gql`
_id
title
}
responseId
values {
_id
field
Expand Down Expand Up @@ -56,6 +57,7 @@ export const GET_RESPONSE_BY_COUNT = gql`
_id
title
}
responseId
values {
_id
field
Expand Down Expand Up @@ -96,6 +98,7 @@ export const GET_RESPONSES = gql`
query MyQuery(
$formId: ID!
$parentId: ID
$responseId: ID
$page: Int
$limit: Int
$search: String
Expand All @@ -105,6 +108,7 @@ export const GET_RESPONSES = gql`
getResponses(
formId: $formId
parentId: $parentId
responseId: $responseId
page: $page
limit: $limit
search: $search
Expand All @@ -120,6 +124,7 @@ export const GET_RESPONSES = gql`
_id
title
}
responseId
values {
_id
field
Expand Down Expand Up @@ -172,6 +177,7 @@ export const GET_MY_RESPONSES = gql`
_id
title
}
responseId
values {
_id
field
Expand Down
1 change: 1 addition & 0 deletions packages/shared/graphql/subscription/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const RESPONSE_SUB = gql`
_id
title
}
responseId
values {
_id
field
Expand Down
12 changes: 12 additions & 0 deletions packages/shared/hooks/list/listItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ export function useGetListItemById(_id) {
return { data };
}

export async function getListItem(_id) {
try {
const response = await apolloClient.query({
query: GET_LIST_ITEM_BY_ID,
variables: { _id },
});
return response;
} catch (e) {
console.log(e);
}
}

export function useGetListItemsByType({ types = [] }: any) {
const [state, setState] = useState({
search: '',
Expand Down
5 changes: 3 additions & 2 deletions packages/shared/hooks/response/createUpdateResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const getValues = (values, fields) => {
return newValues;
};

export function useCreateUpdateResponse({ onAlert }: IHooksProps, parentId) {
export function useCreateUpdateResponse({ onAlert }: IHooksProps, parentId, responseId?: string) {
const [createMutation, { loading: createLoading }] = useMutation(CREATE_RESPONSE);
const [updateMutation, { loading: updateLoading }] = useMutation(UPDATE_RESPONSE);

Expand All @@ -30,8 +30,9 @@ export function useCreateUpdateResponse({ onAlert }: IHooksProps, parentId) {
const values = getValues(payload.values, fields);
payload = {
...payload,
parentId,
values: values.map((m) => JSON.parse(JSON.stringify(m), omitTypename)),
parentId,
responseId,
};
let response = null;
if (edit) {
Expand Down
31 changes: 0 additions & 31 deletions packages/shared/hooks/response/createUpdateResponseParent.ts

This file was deleted.

3 changes: 2 additions & 1 deletion packages/shared/hooks/response/getResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export function useGetResponses(
parentId: string = null,
formField = null,
onlyMy = false,
responseId: string = null,
) {
const [subsribed, setSubsribed] = useState(false);
const [state, setState] = useState({
Expand All @@ -27,7 +28,7 @@ export function useGetResponses(
});

const { data, error, loading, subscribeToMore, refetch } = useQuery(GET_RESPONSES, {
variables: { ...state, formId, parentId, onlyMy },
variables: { ...state, formId, parentId, responseId, onlyMy },
fetchPolicy: 'cache-and-network',
});

Expand Down
1 change: 0 additions & 1 deletion packages/shared/hooks/response/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export { useGetResponse, useGetResponses, useGetResponseByCount } from './getResponse';
export { useCreateUpdateResponse } from './createUpdateResponse';
export { useCreateUpdateResponseParent } from './createUpdateResponseParent';
export { useDeleteResponse } from './deleteResponse';
export { useGetMyResponses } from './getMyResponses';
export { useCreateBulkResponse } from './createBulkResponse';
3 changes: 3 additions & 0 deletions packages/web/src/components/form2/FormFieldsValue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ interface IProps {
handleValueChange: any;
authorized: boolean;
pageId?: string;
responseId?: string;
layouts: any;
disableGrid?: boolean;
onLayoutChange?: (layouts: any) => void;
Expand All @@ -43,6 +44,7 @@ export default function FormFieldsValue({
handleValueChange,
authorized,
pageId,
responseId,
layouts = {},
disableGrid = true,
onLayoutChange,
Expand Down Expand Up @@ -94,6 +96,7 @@ export default function FormFieldsValue({
<FormViewWrapper
formId={field.form?._id}
parentId={pageId}
responseId={responseId}
layouts={layouts}
customSettings={field?.options?.settings?.active && field?.options?.settings}
isPageOwner={authorized}
Expand Down
22 changes: 12 additions & 10 deletions packages/web/src/components/form2/FormView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ import DeleteIcon from '@material-ui/icons/Delete';
import { ArrowBackIosRounded, ArrowForwardIosRounded } from '@material-ui/icons';
import { getForm } from '@frontend/shared/hooks/form/getForm';
import { getResponse, useGetResponses } from '@frontend/shared/hooks/response/getResponse';
import {
useCreateUpdateResponse,
useCreateUpdateResponseParent,
} from '@frontend/shared/hooks/response';
import { useCreateUpdateResponse } from '@frontend/shared/hooks/response';
import ResponseList from '../response/ResponseList';
import InputGroup from '../common/InputGroup';
import LoadingButton from '../common/LoadingButton';
Expand All @@ -35,6 +32,7 @@ import SelectResponse, { getLabel } from '../response/SelectResponse';
interface IProps {
form: any;
parentId?: string;
responseId?: string;
createCallback?: (response: any) => void;
setResponded?: () => void;
isPageOwner?: boolean;
Expand Down Expand Up @@ -66,6 +64,7 @@ const initialState = {
export default function FormViewWrapper({
form,
parentId,
responseId,
createCallback,
setResponded,
layouts,
Expand All @@ -74,16 +73,18 @@ export default function FormViewWrapper({
const { handleCreateUpdateResponse, createLoading } = useCreateUpdateResponse(
{ onAlert },
parentId,
responseId,
);

// const { handleCreateUpdateResponseParent, updateParentLoading } = useCreateUpdateResponseParent(
// { onAlert },
// parentId,
// );

const showOnlyMyResponses = !isPageOwner && form?.settings?.onlyMyResponses;

const { data, error, refetch } = useGetResponses(form?._id, parentId, null, showOnlyMyResponses);
const { data, error, refetch } = useGetResponses(
form?._id,
parentId,
null,
showOnlyMyResponses,
responseId,
);
const [state, setState] = useState(initialState);
const authenticated = useSelector(({ auth }: any) => auth.authenticated);
const [showOverlayResult, setShowOverlayResult] = useState(true);
Expand Down Expand Up @@ -282,6 +283,7 @@ export default function FormViewWrapper({
layouts={layouts}
form={form}
parentId={parentId}
responseId={responseId}
showOnlyMyResponses={showOnlyMyResponses}
/>
)}
Expand Down
3 changes: 3 additions & 0 deletions packages/web/src/components/form2/FormViewWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import NotFound from '../common/NotFound';
interface IProps {
formId: string;
parentId?: string;
responseId?: string;
createCallback?: (response: any) => void;
customSettings?: any;
isPageOwner?: boolean;
Expand All @@ -15,6 +16,7 @@ interface IProps {
export default function FormViewWrapper({
formId,
parentId,
responseId,
createCallback,
customSettings,
isPageOwner,
Expand All @@ -34,6 +36,7 @@ export default function FormViewWrapper({
<FormView
form={{ ...data.getForm, settings: customSettings || data.getForm?.settings }}
parentId={parentId}
responseId={responseId}
createCallback={createCallback}
isPageOwner={isPageOwner}
layouts={layouts}
Expand Down
Loading

0 comments on commit d797699

Please sign in to comment.